aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:45:28 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:45:28 +0200
commit40fa5882a2c73f8c075403b7ec85870f04deda07 (patch)
tree97a7708e159721f92d643ceb802ee18143d78191 /worktree_status.go
parentff18ce3751ad80cfd0297845872ba1d796c36ca5 (diff)
downloadgo-git-40fa5882a2c73f8c075403b7ec85870f04deda07.tar.gz
worktree: Commit method implementation
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 8dc743d..46953c7 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -43,16 +43,16 @@ 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
- s.File(ch.From.String()).Worktree = Unmodified
case merkletrie.Insert:
s.File(ch.To.String()).Staging = Added
- s.File(ch.To.String()).Worktree = Unmodified
case merkletrie.Modify:
s.File(ch.To.String()).Staging = Modified
- s.File(ch.To.String()).Worktree = Unmodified
}
}
@@ -67,19 +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
+ 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 {