diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
commit | b8b61e74469e0d2662e7d690eee14893f91fe259 (patch) | |
tree | 1933fe53200d98ad2c557d034609408641ce2900 /worktree_status.go | |
parent | 40fa5882a2c73f8c075403b7ec85870f04deda07 (diff) | |
parent | e80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff) | |
download | go-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.go | 36 |
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()) |