aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--worktree.go2
-rw-r--r--worktree_test.go32
2 files changed, 33 insertions, 1 deletions
diff --git a/worktree.go b/worktree.go
index 73e638a..4aeae01 100644
--- a/worktree.go
+++ b/worktree.go
@@ -771,7 +771,7 @@ func (w *Worktree) doClean(status Status, opts *CleanOptions, dir string, files
}
}
- if opts.Dir {
+ if opts.Dir && dir != "" {
return doCleanDirectories(w.Filesystem, dir)
}
return nil
diff --git a/worktree_test.go b/worktree_test.go
index 8a7586a..1086735 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -1826,7 +1826,39 @@ func (s *WorktreeSuite) TestClean(c *C) {
// An empty dir should be deleted, as well.
_, err = fs.Lstat("pkgA")
c.Assert(err, ErrorMatches, ".*(no such file or directory.*|.*file does not exist)*.")
+}
+
+func (s *WorktreeSuite) TestCleanBare(c *C) {
+ storer := memory.NewStorage()
+
+ r, err := Init(storer, nil)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
+
+ wtfs := memfs.New()
+
+ err = wtfs.MkdirAll("worktree", os.ModePerm)
+ c.Assert(err, IsNil)
+
+ wtfs, err = wtfs.Chroot("worktree")
+ c.Assert(err, IsNil)
+
+ r, err = Open(storer, wtfs)
+ c.Assert(err, IsNil)
+ wt, err := r.Worktree()
+ c.Assert(err, IsNil)
+
+ _, err = wt.Filesystem.Lstat(".")
+ c.Assert(err, IsNil)
+
+ // Clean with Dir: true.
+ err = wt.Clean(&CleanOptions{Dir: true})
+ c.Assert(err, IsNil)
+
+ // Root worktree directory must remain after cleaning
+ _, err = wt.Filesystem.Lstat(".")
+ c.Assert(err, IsNil)
}
func (s *WorktreeSuite) TestAlternatesRepo(c *C) {