Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2018-08-29 00:20:26 +0300
committerJunio C Hamano <gitster@pobox.com>2018-08-30 19:28:02 +0300
commit3a5404333c6c8b5897e78c9dcb711d623035791b (patch)
tree30604b281cb194ab54045d65faa2dc0df71bd2a3 /builtin/worktree.c
parentf4143101cbb26d189f63f2d29875f4acc07b2730 (diff)
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>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index a95fe67da6..c4abbde2b8 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -62,6 +62,11 @@ static int delete_git_dir(const char *id)
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)
{
struct stat st;
@@ -149,7 +154,7 @@ static void prune_worktrees(void)
}
closedir(dir);
if (!show_only)
- rmdir(git_path("worktrees"));
+ delete_worktrees_dir_if_empty();
strbuf_release(&reason);
}
@@ -918,6 +923,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
* from here.
*/
ret |= delete_git_dir(wt->id);
+ delete_worktrees_dir_if_empty();
free_worktrees(worktrees);
return ret;