This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
remote: pull refactor to match default behavior of cgit #511
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"gopkg.in/src-d/go-git.v4/plumbing/filemode" | ||
"gopkg.in/src-d/go-git.v4/plumbing/format/index" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
"gopkg.in/src-d/go-git.v4/plumbing/storer" | ||
"gopkg.in/src-d/go-git.v4/utils/ioutil" | ||
"gopkg.in/src-d/go-git.v4/utils/merkletrie" | ||
|
||
|
@@ -36,6 +37,8 @@ type Worktree struct { | |
// Pull incorporates changes from a remote repository into the current branch. | ||
// Returns nil if the operation is successful, NoErrAlreadyUpToDate if there are | ||
// no changes to be fetched, or an error. | ||
// | ||
// Pull only supports merges where the can be resolved as a fast-forward. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe reword, see previous comment. |
||
func (w *Worktree) Pull(o *PullOptions) error { | ||
return w.PullContext(context.Background(), o) | ||
} | ||
|
@@ -44,6 +47,8 @@ func (w *Worktree) Pull(o *PullOptions) error { | |
// branch. Returns nil if the operation is successful, NoErrAlreadyUpToDate if | ||
// there are no changes to be fetched, or an error. | ||
// | ||
// Pull only supports merges where the can be resolved as a fast-forward. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
// | ||
// The provided Context must be non-nil. If the context expires before the | ||
// operation is complete, an error is returned. The context only affects to the | ||
// transport operations. | ||
|
@@ -52,17 +57,55 @@ func (w *Worktree) PullContext(ctx context.Context, o *PullOptions) error { | |
return err | ||
} | ||
|
||
head, err := w.r.fetchAndUpdateReferences(ctx, &FetchOptions{ | ||
remote, err := w.r.Remote(o.RemoteName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fetchHead, err := remote.fetch(ctx, &FetchOptions{ | ||
RemoteName: o.RemoteName, | ||
Depth: o.Depth, | ||
Auth: o.Auth, | ||
Progress: o.Progress, | ||
}, o.ReferenceName) | ||
}) | ||
|
||
updated := true | ||
if err == NoErrAlreadyUpToDate { | ||
updated = false | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
ref, err := storer.ResolveReference(fetchHead, o.ReferenceName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := w.Reset(&ResetOptions{Commit: head.Hash()}); err != nil { | ||
head, err := w.r.Head() | ||
if err == nil { | ||
if !updated && head.Hash() == ref.Hash() { | ||
return NoErrAlreadyUpToDate | ||
} | ||
|
||
ff, err := isFastForward(w.r.Storer, head.Hash(), ref.Hash()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !ff { | ||
return fmt.Errorf("non-fast-forward update") | ||
} | ||
} | ||
|
||
if err != nil && err != plumbing.ErrReferenceNotFound { | ||
return err | ||
} | ||
|
||
if err := w.updateHEAD(ref.Hash()); err != nil { | ||
return err | ||
} | ||
|
||
if err := w.Reset(&ResetOptions{Commit: ref.Hash()}); err != nil { | ||
return err | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe reword as
Only supports fast-forward merges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is copy from the git documentation