3 test_description='test git worktree list'
7 test_expect_success 'setup' '
11 test_expect_success '"list" all worktrees from main' '
12 echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
13 test_when_finished "rm -rf here && git worktree prune" &&
14 git worktree add --detach here master &&
15 echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
16 git worktree list | sed "s/ */ /g" >actual &&
17 test_cmp expect actual
20 test_expect_success '"list" all worktrees from linked' '
21 echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
22 test_when_finished "rm -rf here && git worktree prune" &&
23 git worktree add --detach here master &&
24 echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
25 git -C here worktree list | sed "s/ */ /g" >actual &&
26 test_cmp expect actual
29 test_expect_success '"list" all worktrees --porcelain' '
30 echo "worktree $(git rev-parse --show-toplevel)" >expect &&
31 echo "HEAD $(git rev-parse HEAD)" >>expect &&
32 echo "branch $(git symbolic-ref HEAD)" >>expect &&
34 test_when_finished "rm -rf here && git worktree prune" &&
35 git worktree add --detach here master &&
36 echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
37 echo "HEAD $(git rev-parse HEAD)" >>expect &&
38 echo "detached" >>expect &&
40 git worktree list --porcelain >actual &&
41 test_cmp expect actual
44 test_expect_success 'bare repo setup' '
45 git init --bare bare1 &&
48 git commit -m"File1: add data" &&
49 git push bare1 master &&
50 git reset --hard HEAD^
53 test_expect_success '"list" all worktrees from bare main' '
54 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
55 git -C bare1 worktree add --detach ../there master &&
56 echo "$(pwd)/bare1 (bare)" >expect &&
57 echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
58 git -C bare1 worktree list | sed "s/ */ /g" >actual &&
59 test_cmp expect actual
62 test_expect_success '"list" all worktrees --porcelain from bare main' '
63 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
64 git -C bare1 worktree add --detach ../there master &&
65 echo "worktree $(pwd)/bare1" >expect &&
66 echo "bare" >>expect &&
68 echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect &&
69 echo "HEAD $(git -C there rev-parse HEAD)" >>expect &&
70 echo "detached" >>expect &&
72 git -C bare1 worktree list --porcelain >actual &&
73 test_cmp expect actual
76 test_expect_success '"list" all worktrees from linked with a bare main' '
77 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
78 git -C bare1 worktree add --detach ../there master &&
79 echo "$(pwd)/bare1 (bare)" >expect &&
80 echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
81 git -C there worktree list | sed "s/ */ /g" >actual &&
82 test_cmp expect actual
85 test_expect_success 'bare repo cleanup' '