Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worktree: Don't remove root directory when cleaning #230

Merged
merged 1 commit into from Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion worktree.go
Expand Up @@ -769,7 +769,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
Expand Down
32 changes: 32 additions & 0 deletions worktree_test.go
Expand Up @@ -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) {
Expand Down