diff options
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/repository.go b/repository.go index d9a1d7e..bb59afe 100644 --- a/repository.go +++ b/repository.go @@ -340,11 +340,11 @@ func (r *Repository) clone(o *CloneOptions) error { return err } - if _, err := r.updateReferences(c.Fetch, o.ReferenceName, head); err != nil { + if _, err := r.updateReferences(c.Fetch, head); err != nil { return err } - if err := r.updateWorktree(); err != nil { + if err := r.updateWorktree(head.Name()); err != nil { return err } @@ -429,7 +429,7 @@ func (r *Repository) updateRemoteConfig(remote *Remote, o *CloneOptions, } func (r *Repository) updateReferences(spec []config.RefSpec, - headName plumbing.ReferenceName, resolvedHead *plumbing.Reference) (updated bool, err error) { + resolvedHead *plumbing.Reference) (updated bool, err error) { if !resolvedHead.IsBranch() { // Detached HEAD mode @@ -534,7 +534,7 @@ func (r *Repository) Pull(o *PullOptions) error { return err } - refsUpdated, err := r.updateReferences(remote.c.Fetch, o.ReferenceName, head) + refsUpdated, err := r.updateReferences(remote.c.Fetch, head) if err != nil { return err } @@ -547,7 +547,7 @@ func (r *Repository) Pull(o *PullOptions) error { return NoErrAlreadyUpToDate } - if err := r.updateWorktree(); err != nil { + if err := r.updateWorktree(head.Name()); err != nil { return err } @@ -560,22 +560,24 @@ func (r *Repository) Pull(o *PullOptions) error { return nil } -func (r *Repository) updateWorktree() error { +func (r *Repository) updateWorktree(branch plumbing.ReferenceName) error { if r.wt == nil { return nil } - w, err := r.Worktree() + b, err := r.Reference(branch, true) if err != nil { return err } - h, err := r.Head() + w, err := r.Worktree() if err != nil { return err } - return w.Checkout(h.Hash()) + return w.Reset(&ResetOptions{ + Commit: b.Hash(), + }) } // Fetch fetches changes from a remote repository. |