diff options
author | Rafael Silva <rafaeloliveira.cs@gmail.com> | 2021-01-27 09:03:09 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-01-30 09:57:35 -0800 |
commit | 9b19a58f66946c5022fbd1dac6384ca3c86b08ff (patch) | |
tree | 07405c2029208be0e06d00d440af7fc2b1e93f5f /t | |
parent | worktree: teach `list --porcelain` to annotate locked worktree (diff) | |
download | tgif-9b19a58f66946c5022fbd1dac6384ca3c86b08ff.tar.xz |
worktree: teach `list` to annotate prunable worktree
The "git worktree list" command shows the absolute path to the worktree,
the commit that is checked out, the name of the branch, and a "locked"
annotation if the worktree is locked, however, it does not indicate
whether the worktree is prunable.
The "prune" command will remove a worktree if it is prunable unless
`--dry-run` option is specified. This could lead to a worktree being
removed without the user realizing before it is too late, in case the
user forgets to pass --dry-run for instance. If the "list" command shows
which worktree is prunable, the user could verify before running
"git worktree prune" and hopefully prevents the working tree to be
removed "accidentally" on the worse case scenario.
Let's teach "git worktree list" to show when a worktree is a prunable
candidate for both default and porcelain format.
In the default format a "prunable" text is appended:
$ git worktree list
/path/to/main aba123 [main]
/path/to/linked 123abc [branch-a]
/path/to/prunable ace127 (detached HEAD) prunable
In the --porcelain format a prunable label is added followed by
its reason:
$ git worktree list --porcelain
...
worktree /path/to/prunable
HEAD abc1234abc1234abc1234abc1234abc1234abc12
detached
prunable gitdir file points to non-existent location
...
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Rafael Silva <rafaeloliveira.cs@gmail.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t2402-worktree-list.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index 39596e4aa9..69342b7280 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -104,6 +104,38 @@ test_expect_success '"list" all worktrees --porcelain with locked reason newline test_cmp expect actual ' +test_expect_success '"list" all worktrees with prunable annotation' ' + test_when_finished "rm -rf prunable unprunable out && git worktree prune" && + git worktree add --detach prunable && + git worktree add --detach unprunable && + rm -rf prunable && + git worktree list >out && + grep "/prunable *[0-9a-f].* prunable$" out && + ! grep "/unprunable *[0-9a-f].* prunable$" +' + +test_expect_success '"list" all worktrees --porcelain with prunable' ' + test_when_finished "rm -rf prunable out && git worktree prune" && + git worktree add --detach prunable && + rm -rf prunable && + git worktree list --porcelain >out && + sed -n "/^worktree .*\/prunable$/,/^$/p" <out >only_prunable && + test_i18ngrep "^prunable gitdir file points to non-existent location$" only_prunable +' + +test_expect_success '"list" all worktrees with prunable consistent with "prune"' ' + test_when_finished "rm -rf prunable unprunable out && git worktree prune" && + git worktree add --detach prunable && + git worktree add --detach unprunable && + rm -rf prunable && + git worktree list >out && + grep "/prunable *[0-9a-f].* prunable$" out && + ! grep "/unprunable *[0-9a-f].* unprunable$" out && + git worktree prune --verbose >out && + test_i18ngrep "^Removing worktrees/prunable" out && + test_i18ngrep ! "^Removing worktrees/unprunable" out +' + test_expect_success 'bare repo setup' ' git init --bare bare1 && echo "data" >file1 && |