aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-11 04:41:16 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-11 04:41:16 +0200
commit116fed7ea746255805f5664d9b6fd7cdb1b52663 (patch)
treec2fa3a6520f4254550eaf17af83a54526864db3f /repository.go
parentaa818a3f77e6ff06765cf8c246f8708df3d190a7 (diff)
downloadgo-git-116fed7ea746255805f5664d9b6fd7cdb1b52663.tar.gz
worktree, status implementation based on merkletrie and reset and checkout implementations
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/repository.go b/repository.go
index 9e325e4..71a53e7 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.