3 test_description
='magic pathspec tests using git-log'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
12 test_commit initial &&
14 git commit --allow-empty -m empty &&
18 test_expect_success
'"git log :/" should not be ambiguous' '
22 test_expect_success
'"git log :/a" should be ambiguous (applied both rev and worktree)' '
24 test_must_fail git log :/a 2>error &&
25 test_grep ambiguous error
28 test_expect_success
'"git log :/a -- " should not be ambiguous' '
32 test_expect_success
'"git log :/detached -- " should find a commit only in HEAD' '
33 test_when_finished "git checkout main" &&
34 git checkout --detach &&
35 test_commit --no-tag detached &&
36 test_commit --no-tag something-else &&
40 test_expect_success
'"git log :/detached -- " should not find an orphaned commit' '
41 test_must_fail git log :/detached --
44 test_expect_success
'"git log :/detached -- " should find HEAD only of own worktree' '
45 git worktree add other-tree HEAD &&
46 git -C other-tree checkout --detach &&
48 git -C other-tree commit --allow-empty -m other-detached &&
49 git -C other-tree log :/other-detached -- &&
50 test_must_fail git log :/other-detached --
53 test_expect_success
'"git log -- :/a" should not be ambiguous' '
57 test_expect_success
'"git log :/any/path/" should not segfault' '
58 test_must_fail git log :/any/path/
61 # This differs from the ":/a" check above in that :/in looks like a pathspec,
62 # but doesn't match an actual file.
63 test_expect_success
'"git log :/in" should not be ambiguous' '
67 test_expect_success
'"git log :" should be ambiguous' '
68 test_must_fail git log : 2>error &&
69 test_grep ambiguous error
72 test_expect_success
'git log -- :' '
76 test_expect_success
'git log HEAD -- :/' '
77 initial=$(git rev-parse --short HEAD^) &&
78 cat >expected <<-EOF &&
81 (cd sub && git log --oneline HEAD -- :/ >../actual) &&
82 test_cmp expected actual
85 test_expect_success
'"git log :^sub" is not ambiguous' '
89 test_expect_success
'"git log :^does-not-exist" does not match anything' '
90 test_must_fail git log :^does-not-exist
93 test_expect_success
'"git log :!" behaves the same as :^' '
95 test_must_fail git log :!does-not-exist
98 test_expect_success
'"git log :(exclude)sub" is not ambiguous' '
99 git log ":(exclude)sub"
102 test_expect_success
'"git log :(exclude)sub --" must resolve as an object' '
103 test_must_fail git log ":(exclude)sub" --
106 test_expect_success
'"git log :(unknown-magic) complains of bogus magic' '
107 test_must_fail git log ":(unknown-magic)" 2>error &&
108 test_grep pathspec.magic error
111 test_expect_success
'command line pathspec parsing for "git log"' '
115 git commit -m "add an empty a" --allow-empty &&
117 git commit -a -m "update a to 1" &&
118 git checkout HEAD^ &&
120 git commit -a -m "update a to 2" &&
121 test_must_fail git merge main &&
126 test_expect_success
'tree_entry_interesting does not match past submodule boundaries' '
127 test_when_finished "rm -rf repo submodule" &&
128 test_config_global protocol.file.allow always &&
129 git init submodule &&
130 test_commit -C submodule initial &&
133 git -C repo add "[bracket]" &&
135 git -C repo commit -m bracket &&
136 git -C repo rev-list HEAD -- "[bracket]" >expect &&
138 git -C repo submodule add ../submodule &&
140 git -C repo commit -m submodule &&
142 git -C repo rev-list HEAD -- "[bracket]" >actual &&
143 test_cmp expect actual