Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 81dbc6a

Browse files
author
Oleg Sklyar
committed
Adds test that checkout possible with untracked files under gitignore
1 parent dcdd9a7 commit 81dbc6a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

worktree_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,35 @@ func (s *WorktreeSuite) testCheckoutBisect(c *C, url string) {
307307
})
308308
}
309309

310+
func (s *WorktreeSuite) TestCheckoutWithGitignore(c *C) {
311+
fs := memfs.New()
312+
w := &Worktree{
313+
r: s.Repository,
314+
fs: fs,
315+
}
316+
317+
err := w.Checkout(&CheckoutOptions{})
318+
c.Assert(err, IsNil)
319+
320+
f, _ := fs.Create("file")
321+
f.Close()
322+
323+
err = w.Checkout(&CheckoutOptions{})
324+
c.Assert(err.Error(), Equals, "worktree contains unstagged changes")
325+
326+
f, _ = fs.Create(".gitignore")
327+
f.Write([]byte("file"))
328+
f.Close()
329+
330+
err = w.Checkout(&CheckoutOptions{})
331+
c.Assert(err.Error(), Equals, "worktree contains unstagged changes")
332+
333+
w.Add(".gitignore")
334+
335+
err = w.Checkout(&CheckoutOptions{})
336+
c.Assert(err, IsNil)
337+
}
338+
310339
func (s *WorktreeSuite) TestStatus(c *C) {
311340
fs := memfs.New()
312341
w := &Worktree{
@@ -458,10 +487,7 @@ func (s *WorktreeSuite) TestStatusModified(c *C) {
458487
}
459488

460489
func (s *WorktreeSuite) TestStatusIgnored(c *C) {
461-
dir, _ := ioutil.TempDir("", "status")
462-
defer os.RemoveAll(dir)
463-
464-
fs := osfs.New(filepath.Join(dir, "worktree"))
490+
fs := memfs.New()
465491
w := &Worktree{
466492
r: s.Repository,
467493
fs: fs,

0 commit comments

Comments
 (0)