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