]>
Commit | Line | Data |
---|---|---|
bb9c03b8 MR |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git worktree list' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | test_commit init | |
9 | ' | |
10 | ||
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 | |
18 | ' | |
19 | ||
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 | |
27 | ' | |
28 | ||
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 && | |
33 | echo >>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 && | |
39 | echo >>expect && | |
40 | git worktree list --porcelain >actual && | |
41 | test_cmp expect actual | |
42 | ' | |
43 | ||
44 | test_expect_success 'bare repo setup' ' | |
45 | git init --bare bare1 && | |
46 | echo "data" >file1 && | |
47 | git add file1 && | |
48 | git commit -m"File1: add data" && | |
49 | git push bare1 master && | |
50 | git reset --hard HEAD^ | |
51 | ' | |
52 | ||
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 | |
60 | ' | |
61 | ||
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 && | |
67 | echo >>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 && | |
71 | echo >>expect && | |
72 | git -C bare1 worktree list --porcelain >actual && | |
73 | test_cmp expect actual | |
74 | ' | |
75 | ||
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 | |
83 | ' | |
84 | ||
85 | test_expect_success 'bare repo cleanup' ' | |
86 | rm -rf bare1 | |
87 | ' | |
88 | ||
89 | test_done |