Skip to content

Commit

Permalink
fix: prune detached worktrees on cleanup
Browse files Browse the repository at this point in the history
These are not in any way harmful, but they are also not helpful,
and for long-standing cache directories, they can clutter things
up for no good reason.
  • Loading branch information
nisimond authored and retr0h committed Feb 3, 2024
1 parent 654a564 commit c316461
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (g *Git) Worktree(
// this is just junk data in our use case, so get rid of it
if err == nil {
_ = os.Remove(filepath.Join(dst, ".git"))
_ = g.execManager.RunCmdInDir("git", []string{"worktree", "prune", "--verbose"}, cloneDir)
}
return err
}
3 changes: 3 additions & 0 deletions internal/git/git_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (suite *GitManagerPublicTestSuite) TestWorktreeOk() {
suite.mockExec.EXPECT().
RunCmdInDir("git", []string{"worktree", "add", "--force", suite.dstDir, suite.gitVersion}, suite.cloneDir).
Return(nil)
suite.mockExec.EXPECT().
RunCmdInDir("git", []string{"worktree", "prune", "--verbose"}, suite.cloneDir).
Return(nil)
err := suite.gm.Worktree(suite.cloneDir, suite.gitVersion, suite.dstDir)
assert.NoError(suite.T(), err)
}
Expand Down

0 comments on commit c316461

Please sign in to comment.