Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): extract pruneWorktree helper for idiomatic defer cancel

yushen14beaa6ce2cf
diff --git a/server/internal/daemon/gc.go b/server/internal/daemon/gc.go
index 6e1e4e80ee..0b9ec0a7ae 100644
--- a/server/internal/daemon/gc.go
+++ b/server/internal/daemon/gc.go
@@ -204,20 +204,24 @@ func (d *Daemon) pruneRepoWorktrees(workspacesRoot string) {
if !isBareRepo(barePath) {
continue
}
- ctx, cancel := context.WithTimeout(context.Background(), gitCmdTimeout)
- cmd := exec.CommandContext(ctx, "git", "-C", barePath, "worktree", "prune")
- if out, err := cmd.CombinedOutput(); err != nil {
- d.logger.Warn("gc: worktree prune failed",
- "repo", barePath,
- "output", strings.TrimSpace(string(out)),
- "error", err,
- )
- }
- cancel()
+ d.pruneWorktree(barePath)
}
}
}
+func (d *Daemon) pruneWorktree(barePath string) {
+ ctx, cancel := context.WithTimeout(context.Background(), gitCmdTimeout)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, "git", "-C", barePath, "worktree", "prune")
+ if out, err := cmd.CombinedOutput(); err != nil {
+ d.logger.Warn("gc: worktree prune failed",
+ "repo", barePath,
+ "output", strings.TrimSpace(string(out)),
+ "error", err,
+ )
+ }
+}
+
// isBareRepo checks if a path looks like a bare git repository.
func isBareRepo(path string) bool {
if _, err := os.Stat(filepath.Join(path, "HEAD")); err != nil {