Durable - sampling, the ability to reinstall?

Using ruggedas you perform the following steps: fetch, pulland rebase?

I am using a branch developmentand reviewing its documentation found here as a guide to the class Remote.

EDIT: Since it git pullis simply a shorthand for git fetchand git merge FETCH_HEAD, the best issue is implementation git fetch, git mergeand git rebase.

+4
source share
2 answers

git fetch:

remote = Rugged::Remote.lookup(repo, "origin")
remote.connect(:fetch) do |r|
  r.download
  r.update_tips!
end

git merge:

merge_index = repo.merge_commits(
  Rugged::Branches.lookup(repo, "master").tip,
  Rugged::Branches.lookup(repo, "origin/master").tip
)

raise "Conflict detected!" if merge_index.conflicts?

merge_commit = Rugged::Commit.create(repo, {
  parents: [
    Rugged::Branches.lookup(repo, "master").tip,
    Rugged::Branches.lookup(repo, "origin/master").tip
  ],
  tree: merge_index.write_tree(repo),
  message: 'Merged `origin/master` into `master`',
  author:    { name: "User", email: "example@test.com" },
  committer: { name: "User", email: "example@test.com" },
  update_ref: 'master'
})

git rebase:

Rebasing has not yet been implemented in libgit2 and is therefore not available in Rugged.


, , API git. , (, / pull), .

+11

, , . . pull, fetch, . ,

repo.fetch('origin', [repo.head.name], credentials: credits)

, , - , , . . , , git , . , . , , , , .

, , ( ),

ref_name = repo.head.name                            # refs/heads/branchname
branch_name = ref_name.sub(/^refs\/heads\//, '')     # branchname
remote_name = "#{remote}/#{branch_name}"             # origin/branchname
remote_ref = "refs/heads/#{remote_name}"             # refs/heads/origin/branchname

local_branch = repository.branches[branch_name]
remote_branch = repository.branches[remote_name]

index = repo.merge_commits(local_branch.target, remote_branch.target)

options = {
  author:     { time: Time.now }.merge(author),
  committer:  { time: Time.now }.merge(committer),
  message:    'merged',
  parents:    [
    local_branch.target,
    remote_branch.target
  ],
  tree:       index.write_tree(repository),
  update_ref: 'HEAD'
}
Rugged::Commit.create repo, options

, . . - . . , .

- , , ? - 0.22.0b3

1

repo.checkout ref_name, strategy: :force

Update2

,

r = repo.remotes[remote]
r.fetch(credentials: git_credentials)
r.save
+4

Source: https://habr.com/ru/post/1527413/


All Articles