trailer: streamline trailer item create and add
[git/debian.git] / t / t2027-worktree-list.sh
blob1b1b65a6b0fc7ace4e18e8642a6c47631d7e6a43
1 #!/bin/sh
3 test_description='test git worktree list'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit init
11 test_expect_success 'rev-parse --git-common-dir on main worktree' '
12 git rev-parse --git-common-dir >actual &&
13 echo .git >expected &&
14 test_cmp expected actual &&
15 mkdir sub &&
16 git -C sub rev-parse --git-common-dir >actual2 &&
17 echo sub/.git >expected2 &&
18 test_cmp expected2 actual2
21 test_expect_success '"list" all worktrees from main' '
22 echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
23 test_when_finished "rm -rf here && git worktree prune" &&
24 git worktree add --detach here master &&
25 echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
26 git worktree list | sed "s/ */ /g" >actual &&
27 test_cmp expect actual
30 test_expect_success '"list" all worktrees from linked' '
31 echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
32 test_when_finished "rm -rf here && git worktree prune" &&
33 git worktree add --detach here master &&
34 echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
35 git -C here worktree list | sed "s/ */ /g" >actual &&
36 test_cmp expect actual
39 test_expect_success '"list" all worktrees --porcelain' '
40 echo "worktree $(git rev-parse --show-toplevel)" >expect &&
41 echo "HEAD $(git rev-parse HEAD)" >>expect &&
42 echo "branch $(git symbolic-ref HEAD)" >>expect &&
43 echo >>expect &&
44 test_when_finished "rm -rf here && git worktree prune" &&
45 git worktree add --detach here master &&
46 echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
47 echo "HEAD $(git rev-parse HEAD)" >>expect &&
48 echo "detached" >>expect &&
49 echo >>expect &&
50 git worktree list --porcelain >actual &&
51 test_cmp expect actual
54 test_expect_success 'bare repo setup' '
55 git init --bare bare1 &&
56 echo "data" >file1 &&
57 git add file1 &&
58 git commit -m"File1: add data" &&
59 git push bare1 master &&
60 git reset --hard HEAD^
63 test_expect_success '"list" all worktrees from bare main' '
64 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
65 git -C bare1 worktree add --detach ../there master &&
66 echo "$(pwd)/bare1 (bare)" >expect &&
67 echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
68 git -C bare1 worktree list | sed "s/ */ /g" >actual &&
69 test_cmp expect actual
72 test_expect_success '"list" all worktrees --porcelain from bare main' '
73 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
74 git -C bare1 worktree add --detach ../there master &&
75 echo "worktree $(pwd)/bare1" >expect &&
76 echo "bare" >>expect &&
77 echo >>expect &&
78 echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect &&
79 echo "HEAD $(git -C there rev-parse HEAD)" >>expect &&
80 echo "detached" >>expect &&
81 echo >>expect &&
82 git -C bare1 worktree list --porcelain >actual &&
83 test_cmp expect actual
86 test_expect_success '"list" all worktrees from linked with a bare main' '
87 test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
88 git -C bare1 worktree add --detach ../there master &&
89 echo "$(pwd)/bare1 (bare)" >expect &&
90 echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
91 git -C there worktree list | sed "s/ */ /g" >actual &&
92 test_cmp expect actual
95 test_expect_success 'bare repo cleanup' '
96 rm -rf bare1
99 test_done