aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-09-01 17:26:52 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-09-01 17:26:52 +0200
commitf1e58e0d30095cf768ff04d379b5e4145a874be8 (patch)
tree1922e3a721c4c19889557f96108076c325b95fbd /worktree_status.go
parent3ca370277427c5d508f0dedacbd559523a305121 (diff)
downloadgo-git-f1e58e0d30095cf768ff04d379b5e4145a874be8.tar.gz
Worktree.Reset ignore untracked files on Merge mode
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go42
1 files changed, 29 insertions, 13 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 9b0773e..24d0534 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -65,7 +65,7 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
}
}
- right, err := w.diffStagingWithWorktree()
+ right, err := w.diffStagingWithWorktree(false)
if err != nil {
return nil, err
}
@@ -104,7 +104,7 @@ func nameFromAction(ch *merkletrie.Change) string {
return name
}
-func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
+func (w *Worktree) diffStagingWithWorktree(reverse bool) (merkletrie.Changes, error) {
idx, err := w.r.Storer.Index()
if err != nil {
return nil, err
@@ -117,11 +117,19 @@ func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
}
to := filesystem.NewRootNode(w.Filesystem, submodules)
- res, err := merkletrie.DiffTree(from, to, diffTreeIsEquals)
- if err == nil {
- res = w.excludeIgnoredChanges(res)
+
+ var c merkletrie.Changes
+ if reverse {
+ c, err = merkletrie.DiffTree(to, from, diffTreeIsEquals)
+ } else {
+ c, err = merkletrie.DiffTree(from, to, diffTreeIsEquals)
}
- return res, err
+
+ if err != nil {
+ return nil, err
+ }
+
+ return w.excludeIgnoredChanges(c), nil
}
func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
@@ -179,27 +187,35 @@ func (w *Worktree) getSubmodulesStatus() (map[string]plumbing.Hash, error) {
}
func (w *Worktree) diffCommitWithStaging(commit plumbing.Hash, reverse bool) (merkletrie.Changes, error) {
- idx, err := w.r.Storer.Index()
- if err != nil {
- return nil, err
- }
-
- var from noder.Noder
+ var t *object.Tree
if !commit.IsZero() {
c, err := w.r.CommitObject(commit)
if err != nil {
return nil, err
}
- t, err := c.Tree()
+ t, err = c.Tree()
if err != nil {
return nil, err
}
+ }
+ return w.diffTreeWithStaging(t, reverse)
+}
+
+func (w *Worktree) diffTreeWithStaging(t *object.Tree, reverse bool) (merkletrie.Changes, error) {
+ var from noder.Noder
+ if t != nil {
from = object.NewTreeRootNode(t)
}
+ idx, err := w.r.Storer.Index()
+ if err != nil {
+ return nil, err
+ }
+
to := mindex.NewRootNode(idx)
+
if reverse {
return merkletrie.DiffTree(to, from, diffTreeIsEquals)
}