aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-16 23:55:24 -0700
committerGitHub <noreply@github.com>2017-07-16 23:55:24 -0700
commit046b15e533b9f3237bf34fbd8da285df921fbca4 (patch)
tree3a82505ca8f144b10a55dde9923f6fced89ae03b /worktree_status.go
parent3ba215f3da8f10834313b5a4de58ca01400e248f (diff)
parentaa74b3ab06c260c2160dcb6110edad888ae1cc25 (diff)
downloadgo-git-046b15e533b9f3237bf34fbd8da285df921fbca4.tar.gz
Merge pull request #480 from mcuadros/empty-status
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)
}