worktree: delete .git/worktrees if empty after 'remove'
For cleanliness, "git worktree prune" deletes the .git/worktrees directory if it is empty after pruning is complete. For consistency, make "git worktree remove <path>" likewise delete .git/worktrees if it is empty after the removal. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f4143101cb
commit
3a5404333c
@ -62,6 +62,11 @@ static int delete_git_dir(const char *id)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void delete_worktrees_dir_if_empty(void)
|
||||||
|
{
|
||||||
|
rmdir(git_path("worktrees")); /* ignore failed removal */
|
||||||
|
}
|
||||||
|
|
||||||
static int prune_worktree(const char *id, struct strbuf *reason)
|
static int prune_worktree(const char *id, struct strbuf *reason)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -149,7 +154,7 @@ static void prune_worktrees(void)
|
|||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if (!show_only)
|
if (!show_only)
|
||||||
rmdir(git_path("worktrees"));
|
delete_worktrees_dir_if_empty();
|
||||||
strbuf_release(&reason);
|
strbuf_release(&reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -918,6 +923,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
|
|||||||
* from here.
|
* from here.
|
||||||
*/
|
*/
|
||||||
ret |= delete_git_dir(wt->id);
|
ret |= delete_git_dir(wt->id);
|
||||||
|
delete_worktrees_dir_if_empty();
|
||||||
|
|
||||||
free_worktrees(worktrees);
|
free_worktrees(worktrees);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -173,4 +173,16 @@ test_expect_success 'remove locked worktree (force)' '
|
|||||||
git worktree remove --force --force gumby
|
git worktree remove --force --force gumby
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'remove cleans up .git/worktrees when empty' '
|
||||||
|
git init moog &&
|
||||||
|
(
|
||||||
|
cd moog &&
|
||||||
|
test_commit bim &&
|
||||||
|
git worktree add --detach goom &&
|
||||||
|
test_path_exists .git/worktrees &&
|
||||||
|
git worktree remove goom &&
|
||||||
|
test_path_is_missing .git/worktrees
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user