Skip to content

Commit 189e7e4

Browse files
authored
Merge pull request #1361 from BeChris/issue1176-v5
git: worktree, fix restoring dot slash files (backported to v5). Fixes #1176
2 parents 654815a + 4949135 commit 189e7e4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

worktree.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string, files []string) err
425425
}
426426

427427
func inFiles(files []string, v string) bool {
428+
v = filepath.Clean(v)
428429
for _, s := range files {
429-
if s == v {
430+
if filepath.Clean(s) == v {
430431
return true
431432
}
432433
}

worktree_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ func (s *WorktreeSuite) TestResetHardSubFolders(c *C) {
12531253

12541254
err = fs.MkdirAll("dir", os.ModePerm)
12551255
c.Assert(err, IsNil)
1256-
tf, err := fs.Create("dir/testfile.txt")
1256+
tf, err := fs.Create("./dir/testfile.txt")
12571257
c.Assert(err, IsNil)
12581258
_, err = tf.Write([]byte("testfile content"))
12591259
c.Assert(err, IsNil)
@@ -3196,7 +3196,7 @@ func (s *WorktreeSuite) TestRestoreStaged(c *C) {
31963196
c.Assert(err, Equals, ErrNoRestorePaths)
31973197

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy