aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 10:17:15 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-05-04 10:17:15 +0200
commitb8b61e74469e0d2662e7d690eee14893f91fe259 (patch)
tree1933fe53200d98ad2c557d034609408641ce2900 /worktree_status.go
parent40fa5882a2c73f8c075403b7ec85870f04deda07 (diff)
parente80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff)
downloadgo-git-b8b61e74469e0d2662e7d690eee14893f91fe259.tar.gz
Merge branch 'master' of github.com:src-d/go-git into commit
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go36
1 files changed, 15 insertions, 21 deletions
diff --git a/worktree_status.go b/worktree_status.go
index 46953c7..632f102 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -233,42 +233,36 @@ func (w *Worktree) addOrUpdateFileToIndex(filename string, h plumbing.Hash) erro
return err
}
- _, err = idx.Entry(filename)
- if err == index.ErrEntryNotFound {
- err = w.doAddFileToIndex(idx, filename)
- }
-
- if err != nil {
+ e, err := idx.Entry(filename)
+ if err != nil && err != index.ErrEntryNotFound {
return err
}
- err = w.doUpdateFileToIndex(idx, filename, h)
- if err != nil {
- return err
+ if err == index.ErrEntryNotFound {
+ if err := w.doAddFileToIndex(idx, filename, h); err != nil {
+ return err
+ }
+ } else {
+ if err := w.doUpdateFileToIndex(e, filename, h); err != nil {
+ return err
+ }
}
-
return w.r.Storer.SetIndex(idx)
}
-func (w *Worktree) doAddFileToIndex(idx *index.Index, filename string) error {
- idx.Entries = append(idx.Entries, &index.Entry{
- Name: filename,
- })
+func (w *Worktree) doAddFileToIndex(idx *index.Index, filename string, h plumbing.Hash) error {
+ e := &index.Entry{Name: filename}
+ idx.Entries = append(idx.Entries, e)
- return nil
+ return w.doUpdateFileToIndex(e, filename, h)
}
-func (w *Worktree) doUpdateFileToIndex(idx *index.Index, filename string, h plumbing.Hash) error {
+func (w *Worktree) doUpdateFileToIndex(e *index.Entry, filename string, h plumbing.Hash) error {
info, err := w.fs.Stat(filename)
if err != nil {
return err
}
- e, err := idx.Entry(filename)
- if err != nil {
- return err
- }
-
e.Hash = h
e.ModifiedAt = info.ModTime()
e.Mode, err = filemode.NewFromOSFileMode(info.Mode())