-
Notifications
You must be signed in to change notification settings - Fork 534
Worktree.Add: Support Add deleted files, fixes #571 #577
Conversation
…us its associated test. Fixed, what I think, a false positive in TestFilenameNormalization in worktree_test.go.
I cannot reproduce that error. Any idea why ? |
Its a test randomly failing, don't worry |
worktree_status.go
Outdated
@@ -266,6 +266,23 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) { | |||
return h, err | |||
} | |||
|
|||
func (w *Worktree) removeIfDeleted(path string, hash plumbing.Hash, err error) (plumbing.Hash, error) { | |||
pathError, ok := err.(*os.PathError) | |||
if ok && pathError.Op == "lstat" || w.isErrNotExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the built-in functionos.IsNotExist
?
Codecov Report
@@ Coverage Diff @@
## master #577 +/- ##
==========================================
- Coverage 78.01% 77.46% -0.56%
==========================================
Files 129 129
Lines 9922 9941 +19
==========================================
- Hits 7741 7701 -40
- Misses 1338 1410 +72
+ Partials 843 830 -13
Continue to review full report at Codecov.
|
worktree_status.go
Outdated
@@ -266,6 +266,19 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) { | |||
return h, err | |||
} | |||
|
|||
func (w *Worktree) removeIfDeleted(path string, hash plumbing.Hash, err error) (plumbing.Hash, error) { | |||
pathError, ok := err.(*os.PathError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to do the cast or check if is a lsstat, the function is smart enough for detect any non-existan file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I rather having the if condition where the err
is generated instead of having another function. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
In order to fix the bug mentioned in the issue, I modified the Add method of Worktree to handle the case where a file is removed but is still in the repository.
My fix just ensure that the repo and the filesystem are always in sync.
I also found what I think to be a false positive in the TestFilenameNormalization test.
The wrong file were added.