Skip to content

Commit d462c2e

Browse files
authored
Merge pull request #1359 from BeChris/issue1150-v5
git: worktree_status, fix adding dot slash files to working tree (backported to v5). Fixes #1150
2 parents 32ac23a + b2bb975 commit d462c2e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

worktree_status.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ func (w *Worktree) doAdd(path string, ignorePattern []gitignore.Pattern, skipSta
370370
}
371371
}
372372

373+
path = filepath.Clean(path)
374+
373375
if err != nil || !fi.IsDir() {
374376
added, h, err = w.doAddFile(idx, s, path, ignorePattern)
375377
} else {

worktree_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,66 @@ func (s *WorktreeSuite) TestAddGlob(c *C) {
20072007
c.Assert(file.Worktree, Equals, Unmodified)
20082008
}
20092009

2010+
func (s *WorktreeSuite) TestAddFilenameStartingWithDot(c *C) {
2011+
fs := memfs.New()
2012+
w := &Worktree{
2013+
r: s.Repository,
2014+
Filesystem: fs,
2015+
}
2016+
2017+
err := w.Checkout(&CheckoutOptions{Force: true})
2018+
c.Assert(err, IsNil)
2019+
2020+
idx, err := w.r.Storer.Index()
2021+
c.Assert(err, IsNil)
2022+
c.Assert(idx.Entries, HasLen, 9)
2023+
2024+
err = util.WriteFile(w.Filesystem, "qux", []byte("QUX"), 0o755)
2025+
c.Assert(err, IsNil)
2026+
err = util.WriteFile(w.Filesystem, "baz", []byte("BAZ"), 0o755)
2027+
c.Assert(err, IsNil)
2028+
err = util.WriteFile(w.Filesystem, "foo/bar/baz", []byte("BAZ"), 0o755)
2029+
c.Assert(err, IsNil)
2030+
2031+
_, err = w.Add("./qux")
2032+
c.Assert(err, IsNil)
2033+
2034+
_, err = w.Add("./baz")
2035+
c.Assert(err, IsNil)
2036+
2037+
_, err = w.Add("foo/bar/../bar/./baz")
2038+
c.Assert(err, IsNil)
2039+
2040+
idx, err = w.r.Storer.Index()
2041+
c.Assert(err, IsNil)
2042+
c.Assert(idx.Entries, HasLen, 12)
2043+
2044+
e, err := idx.Entry("qux")
2045+
c.Assert(err, IsNil)
2046+
c.Assert(e.Mode, Equals, filemode.Executable)
2047+
2048+
e, err = idx.Entry("baz")
2049+
c.Assert(err, IsNil)
2050+
c.Assert(e.Mode, Equals, filemode.Executable)
2051+
2052+
status, err := w.Status()
2053+
c.Assert(err, IsNil)
2054+
c.Assert(status, HasLen, 3)
2055+
2056+
file := status.File("qux")
2057+
c.Assert(file.Staging, Equals, Added)
2058+
c.Assert(file.Worktree, Equals, Unmodified)
2059+
2060+
file = status.File("baz")
2061+
c.Assert(file.Staging, Equals, Added)
2062+
c.Assert(file.Worktree, Equals, Unmodified)
2063+
2064+
file = status.File("foo/bar/baz")
2065+
c.Assert(file.Staging, Equals, Added)
2066+
c.Assert(file.Worktree, Equals, Unmodified)
2067+
2068+
}
2069+
20102070
func (s *WorktreeSuite) TestAddGlobErrorNoMatches(c *C) {
20112071
r, _ := Init(memory.NewStorage(), memfs.New())
20122072
w, _ := r.Worktree()

0 commit comments

Comments
 (0)