aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-05 11:34:50 +0200
committerGitHub <noreply@github.com>2017-05-05 11:34:50 +0200
commitced875aec7bef9113e1c37b1b811a59e17dbd138 (patch)
tree3cf652b8cfa94e011d4d7b5addfd13945870cda8 /worktree_status.go
parente80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff)
parent3713157d189a109bdccdb055200defb17297b6de (diff)
downloadgo-git-ced875aec7bef9113e1c37b1b811a59e17dbd138.tar.gz
Merge pull request #375 from mcuadros/commit
worktree: Commit method implementation
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/worktree_status.go b/worktree_status.go
index e6d1745..632f102 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -19,7 +19,7 @@ import (
func (w *Worktree) Status() (Status, error) {
ref, err := w.r.Head()
if err == plumbing.ErrReferenceNotFound {
- return nil, nil
+ return make(Status, 0), nil
}
if err != nil {
@@ -43,6 +43,9 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
return nil, err
}
+ fs := s.File(nameFromAction(&ch))
+ fs.Worktree = Unmodified
+
switch a {
case merkletrie.Delete:
s.File(ch.From.String()).Staging = Deleted
@@ -64,20 +67,34 @@ func (w *Worktree) status(commit plumbing.Hash) (Status, error) {
return nil, err
}
+ fs := s.File(nameFromAction(&ch))
+ if fs.Staging == Untracked {
+ fs.Staging = Unmodified
+ }
+
switch a {
case merkletrie.Delete:
- s.File(ch.From.String()).Worktree = Deleted
+ fs.Worktree = Deleted
case merkletrie.Insert:
- s.File(ch.To.String()).Worktree = Untracked
- s.File(ch.To.String()).Staging = Untracked
+ fs.Worktree = Untracked
+ fs.Staging = Untracked
case merkletrie.Modify:
- s.File(ch.To.String()).Worktree = Modified
+ fs.Worktree = Modified
}
}
return s, nil
}
+func nameFromAction(ch *merkletrie.Change) string {
+ name := ch.To.String()
+ if name == "" {
+ return ch.From.String()
+ }
+
+ return name
+}
+
func (w *Worktree) diffStagingWithWorktree() (merkletrie.Changes, error) {
idx, err := w.r.Storer.Index()
if err != nil {