Skip to content

Commit dd9609a

Browse files
sunshinecogitster
authored andcommitted
worktree: make high-level pruning re-usable
The low-level logic for removing a worktree is well encapsulated in delete_git_dir(). However, high-level details related to pruning a worktree -- such as dealing with verbosity and dry-run mode -- are not encapsulated. Factor out this high-level logic into its own function so it can be re-used as new worktree corruption detectors are added. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b14d40 commit dd9609a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

builtin/worktree.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ static int should_prune_worktree(const char *id, struct strbuf *reason)
133133
return 0;
134134
}
135135

136+
static void prune_worktree(const char *id, const char *reason)
137+
{
138+
if (show_only || verbose)
139+
printf_ln(_("Removing %s/%s: %s"), "worktrees", id, reason);
140+
if (!show_only)
141+
delete_git_dir(id);
142+
}
143+
136144
static void prune_worktrees(void)
137145
{
138146
struct strbuf reason = STRBUF_INIT;
@@ -146,12 +154,7 @@ static void prune_worktrees(void)
146154
strbuf_reset(&reason);
147155
if (!should_prune_worktree(d->d_name, &reason))
148156
continue;
149-
if (show_only || verbose)
150-
printf_ln(_("Removing %s/%s: %s"),
151-
"worktrees", d->d_name, reason.buf);
152-
if (show_only)
153-
continue;
154-
delete_git_dir(d->d_name);
157+
prune_worktree(d->d_name, reason.buf);
155158
}
156159
closedir(dir);
157160
if (!show_only)

0 commit comments

Comments
 (0)