Skip to content

Commit 9ac753f

Browse files
authored
Merge pull request go-git#109 from mruediger/master
Worktre: Pull, report "Already up to date" when local repository ahead of remote
2 parents 16918a5 + 23e21f0 commit 9ac753f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

worktree.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ func (w *Worktree) PullContext(ctx context.Context, o *PullOptions) error {
9393

9494
head, err := w.r.Head()
9595
if err == nil {
96-
if !updated && head.Hash() == ref.Hash() {
96+
headAheadOfRef,err := isFastForward(w.r.Storer, ref.Hash(), head.Hash())
97+
if err != nil {
98+
return err
99+
}
100+
101+
if !updated && headAheadOfRef {
97102
return NoErrAlreadyUpToDate
98103
}
99104

105+
100106
ff, err := isFastForward(w.r.Storer, head.Hash(), ref.Hash())
101107
if err != nil {
102108
return err

worktree_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,26 @@ func (s *RepositorySuite) TestPullAdd(c *C) {
265265
c.Assert(branch.Hash().String(), Not(Equals), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
266266
}
267267

268+
func (s *WorktreeSuite) TestPullAlreadyUptodate(c *C) {
269+
path := fixtures.Basic().ByTag("worktree").One().Worktree().Root()
270+
271+
r, err := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
272+
URL: filepath.Join(path, ".git"),
273+
})
274+
275+
c.Assert(err, IsNil)
276+
277+
w, err := r.Worktree()
278+
c.Assert(err, IsNil)
279+
err = ioutil.WriteFile(filepath.Join(path, "bar"), []byte("bar"), 0755)
280+
c.Assert(err, IsNil)
281+
_, err = w.Commit("bar", &CommitOptions{Author: defaultSignature()})
282+
c.Assert(err, IsNil)
283+
284+
err = w.Pull(&PullOptions{})
285+
c.Assert(err, Equals, NoErrAlreadyUpToDate)
286+
}
287+
268288
func (s *WorktreeSuite) TestCheckout(c *C) {
269289
fs := memfs.New()
270290
w := &Worktree{

0 commit comments

Comments
 (0)