aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
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)
}