aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-13 17:28:00 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-13 17:28:00 +0200
commitaa74b3ab06c260c2160dcb6110edad888ae1cc25 (patch)
tree795d180fb9ad3f9822c2a68f9d9f4b171c1de061 /worktree_status.go
parent6b3a6df29920d39b8308924b3b84178226b56224 (diff)
downloadgo-git-aa74b3ab06c260c2160dcb6110edad888ae1cc25.tar.gz
remote: fix Worktree.Status on empty repository
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go33
1 files changed, 19 insertions, 14 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 728d7a0..a662516 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -24,16 +24,18 @@ var ErrDestinationExists = errors.New("destination exists")
// Status returns the working tree status.
func (w *Worktree) Status() (Status, error) {
+ var hash plumbing.Hash
+
ref, err := w.r.Head()
- if err == plumbing.ErrReferenceNotFound {
- return make(Status, 0), nil
+ if err != nil && err != plumbing.ErrReferenceNotFound {
+ return nil, err
}
- if err != nil {
- return nil, err
+ if err == nil {
+ hash = ref.Hash()
}
- return w.status(ref.Hash())
+ return w.status(hash)
}
func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
@@ -182,19 +184,22 @@ func (w *Worktree) diffCommitWithStaging(commit plumbing.Hash, reverse bool) (me
return nil, err
}
- c, err := w.r.CommitObject(commit)
- if err != nil {
- return nil, err
- }
+ var from noder.Noder
+ if !commit.IsZero() {
+ c, err := w.r.CommitObject(commit)
+ if err != nil {
+ return nil, err
+ }
- t, err := c.Tree()
- if err != nil {
- return nil, err
+ t, err := c.Tree()
+ if err != nil {
+ return nil, err
+ }
+
+ from = object.NewTreeRootNode(t)
}
to := mindex.NewRootNode(idx)
- from := object.NewTreeRootNode(t)
-
if reverse {
return merkletrie.DiffTree(to, from, diffTreeIsEquals)
}