From d97eb302ea848ff6f8f9af50a176734930964b9a Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Thu, 31 Mar 2022 16:21:28 +0000 Subject: worktree: add -z option for list subcommand Add a -z option to be used in conjunction with --porcelain that gives NUL-terminated output. As 'worktree list --porcelain' does not quote worktree paths this enables it to handle worktree paths that contain newlines. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/t2402-worktree-list.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 't') diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index c8a5a0aac6..79e0fce2d9 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -64,6 +64,25 @@ test_expect_success '"list" all worktrees --porcelain' ' test_cmp expect actual ' +test_expect_success '"list" all worktrees --porcelain -z' ' + test_when_finished "rm -rf here _actual actual expect && + git worktree prune" && + printf "worktree %sQHEAD %sQbranch %sQQ" \ + "$(git rev-parse --show-toplevel)" \ + $(git rev-parse HEAD --symbolic-full-name HEAD) >expect && + git worktree add --detach here main && + printf "worktree %sQHEAD %sQdetachedQQ" \ + "$(git -C here rev-parse --show-toplevel)" \ + "$(git rev-parse HEAD)" >>expect && + git worktree list --porcelain -z >_actual && + nul_to_q <_actual >actual && + test_cmp expect actual +' + +test_expect_success '"list" -z fails without --porcelain' ' + test_must_fail git worktree list -z +' + test_expect_success '"list" all worktrees with locked annotation' ' test_when_finished "rm -rf locked unlocked out && git worktree prune" && git worktree add --detach locked main && -- cgit v1.2.3