t5[6-9]*: adjust the references to the default branch name "main"
[git] / t / t4208-log-magic-pathspec.sh
1 #!/bin/sh
2
3 test_description='magic pathspec tests using git-log'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11         test_commit initial &&
12         test_tick &&
13         git commit --allow-empty -m empty &&
14         mkdir sub
15 '
16
17 test_expect_success '"git log :/" should not be ambiguous' '
18         git log :/
19 '
20
21 test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' '
22         : >a &&
23         test_must_fail git log :/a 2>error &&
24         test_i18ngrep ambiguous error
25 '
26
27 test_expect_success '"git log :/a -- " should not be ambiguous' '
28         git log :/a --
29 '
30
31 test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
32         test_when_finished "git checkout main" &&
33         git checkout --detach &&
34         # Must manually call `test_tick` instead of using `test_commit`,
35         # because the latter additionally creates a tag, which would make
36         # the commit reachable not only via HEAD.
37         test_tick &&
38         git commit --allow-empty -m detached &&
39         test_tick &&
40         git commit --allow-empty -m something-else &&
41         git log :/detached --
42 '
43
44 test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
45         test_must_fail git log :/detached --
46 '
47
48 test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' '
49         git worktree add other-tree HEAD &&
50         git -C other-tree checkout --detach &&
51         test_tick &&
52         git -C other-tree commit --allow-empty -m other-detached &&
53         git -C other-tree log :/other-detached -- &&
54         test_must_fail git log :/other-detached --
55 '
56
57 test_expect_success '"git log -- :/a" should not be ambiguous' '
58         git log -- :/a
59 '
60
61 test_expect_success '"git log :/any/path/" should not segfault' '
62         test_must_fail git log :/any/path/
63 '
64
65 # This differs from the ":/a" check above in that :/in looks like a pathspec,
66 # but doesn't match an actual file.
67 test_expect_success '"git log :/in" should not be ambiguous' '
68         git log :/in
69 '
70
71 test_expect_success '"git log :" should be ambiguous' '
72         test_must_fail git log : 2>error &&
73         test_i18ngrep ambiguous error
74 '
75
76 test_expect_success 'git log -- :' '
77         git log -- :
78 '
79
80 test_expect_success 'git log HEAD -- :/' '
81         initial=$(git rev-parse --short HEAD^) &&
82         cat >expected <<-EOF &&
83         $initial initial
84         EOF
85         (cd sub && git log --oneline HEAD -- :/ >../actual) &&
86         test_cmp expected actual
87 '
88
89 test_expect_success '"git log :^sub" is not ambiguous' '
90         git log :^sub
91 '
92
93 test_expect_success '"git log :^does-not-exist" does not match anything' '
94         test_must_fail git log :^does-not-exist
95 '
96
97 test_expect_success  '"git log :!" behaves the same as :^' '
98         git log :!sub &&
99         test_must_fail git log :!does-not-exist
100 '
101
102 test_expect_success '"git log :(exclude)sub" is not ambiguous' '
103         git log ":(exclude)sub"
104 '
105
106 test_expect_success '"git log :(exclude)sub --" must resolve as an object' '
107         test_must_fail git log ":(exclude)sub" --
108 '
109
110 test_expect_success '"git log :(unknown-magic) complains of bogus magic' '
111         test_must_fail git log ":(unknown-magic)" 2>error &&
112         test_i18ngrep pathspec.magic error
113 '
114
115 test_expect_success 'command line pathspec parsing for "git log"' '
116         git reset --hard &&
117         >a &&
118         git add a &&
119         git commit -m "add an empty a" --allow-empty &&
120         echo 1 >a &&
121         git commit -a -m "update a to 1" &&
122         git checkout HEAD^ &&
123         echo 2 >a &&
124         git commit -a -m "update a to 2" &&
125         test_must_fail git merge main &&
126         git add a &&
127         git log --merge -- a
128 '
129
130 test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
131         test_when_finished "rm -rf repo submodule" &&
132         git init submodule &&
133         test_commit -C submodule initial &&
134         git init repo &&
135         >"repo/[bracket]" &&
136         git -C repo add "[bracket]" &&
137         test_tick &&
138         git -C repo commit -m bracket &&
139         git -C repo rev-list HEAD -- "[bracket]" >expect &&
140
141         git -C repo submodule add ../submodule &&
142         test_tick &&
143         git -C repo commit -m submodule &&
144
145         git -C repo rev-list HEAD -- "[bracket]" >actual &&
146         test_cmp expect actual
147 '
148
149 test_done