Merge branch 'main' of github.com:git/git
[alt-git.git] / t / t4208-log-magic-pathspec.sh
blob7f0c1dcc0f0bfbfd746648f4fee1b7588a8f31b8
1 #!/bin/sh
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-lib.sh
10 test_expect_success 'setup' '
11 test_commit initial &&
12 test_tick &&
13 git commit --allow-empty -m empty &&
14 mkdir sub
17 test_expect_success '"git log :/" should not be ambiguous' '
18 git log :/
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
27 test_expect_success '"git log :/a -- " should not be ambiguous' '
28 git log :/a --
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 test_commit --no-tag detached &&
35 test_commit --no-tag something-else &&
36 git log :/detached --
39 test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
40 test_must_fail git log :/detached --
43 test_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 --
52 test_expect_success '"git log -- :/a" should not be ambiguous' '
53 git log -- :/a
56 test_expect_success '"git log :/any/path/" should not segfault' '
57 test_must_fail git log :/any/path/
60 # This differs from the ":/a" check above in that :/in looks like a pathspec,
61 # but doesn't match an actual file.
62 test_expect_success '"git log :/in" should not be ambiguous' '
63 git log :/in
66 test_expect_success '"git log :" should be ambiguous' '
67 test_must_fail git log : 2>error &&
68 test_i18ngrep ambiguous error
71 test_expect_success 'git log -- :' '
72 git log -- :
75 test_expect_success 'git log HEAD -- :/' '
76 initial=$(git rev-parse --short HEAD^) &&
77 cat >expected <<-EOF &&
78 $initial initial
79 EOF
80 (cd sub && git log --oneline HEAD -- :/ >../actual) &&
81 test_cmp expected actual
84 test_expect_success '"git log :^sub" is not ambiguous' '
85 git log :^sub
88 test_expect_success '"git log :^does-not-exist" does not match anything' '
89 test_must_fail git log :^does-not-exist
92 test_expect_success '"git log :!" behaves the same as :^' '
93 git log :!sub &&
94 test_must_fail git log :!does-not-exist
97 test_expect_success '"git log :(exclude)sub" is not ambiguous' '
98 git log ":(exclude)sub"
101 test_expect_success '"git log :(exclude)sub --" must resolve as an object' '
102 test_must_fail git log ":(exclude)sub" --
105 test_expect_success '"git log :(unknown-magic) complains of bogus magic' '
106 test_must_fail git log ":(unknown-magic)" 2>error &&
107 test_i18ngrep pathspec.magic error
110 test_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" &&
120 test_must_fail git merge main &&
121 git add a &&
122 git log --merge -- a
125 test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
126 test_when_finished "rm -rf repo submodule" &&
127 git init submodule &&
128 test_commit -C submodule initial &&
129 git init repo &&
130 >"repo/[bracket]" &&
131 git -C repo add "[bracket]" &&
132 test_tick &&
133 git -C repo commit -m bracket &&
134 git -C repo rev-list HEAD -- "[bracket]" >expect &&
136 git -C repo submodule add ../submodule &&
137 test_tick &&
138 git -C repo commit -m submodule &&
140 git -C repo rev-list HEAD -- "[bracket]" >actual &&
141 test_cmp expect actual
144 test_done