Skip to content

Commit

Permalink
Merge pull request #1361 from BeChris/issue1176-v5
Browse files Browse the repository at this point in the history
git: worktree, fix restoring dot slash files (backported to v5). Fixes #1176
  • Loading branch information
pjbgf authored Jan 15, 2025
2 parents 654815a + 4949135 commit 189e7e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,9 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string, files []string) err
}

func inFiles(files []string, v string) bool {
v = filepath.Clean(v)
for _, s := range files {
if s == v {
if filepath.Clean(s) == v {
return true
}
}
Expand Down
6 changes: 3 additions & 3 deletions worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ func (s *WorktreeSuite) TestResetHardSubFolders(c *C) {

err = fs.MkdirAll("dir", os.ModePerm)
c.Assert(err, IsNil)
tf, err := fs.Create("dir/testfile.txt")
tf, err := fs.Create("./dir/testfile.txt")
c.Assert(err, IsNil)
_, err = tf.Write([]byte("testfile content"))
c.Assert(err, IsNil)
Expand Down Expand Up @@ -3196,7 +3196,7 @@ func (s *WorktreeSuite) TestRestoreStaged(c *C) {
c.Assert(err, Equals, ErrNoRestorePaths)

// Restore Staged files in 2 groups and confirm status
opts.Files = []string{names[0], names[1]}
opts.Files = []string{names[0], "./" + names[1]}
err = w.Restore(&opts)
c.Assert(err, IsNil)
verifyStatus(c, "Restored First", w, names, []FileStatus{
Expand All @@ -3211,7 +3211,7 @@ func (s *WorktreeSuite) TestRestoreStaged(c *C) {
c.Assert(err, IsNil)
c.Assert(string(contents), Equals, "Foo Bar:11")

opts.Files = []string{names[2], names[3]}
opts.Files = []string{"./" + names[2], names[3]}
err = w.Restore(&opts)
c.Assert(err, IsNil)
verifyStatus(c, "Restored Second", w, names, []FileStatus{
Expand Down

0 comments on commit 189e7e4

Please sign in to comment.