blob: 69643d101d2130fe4f236719870e8929eca709f2 [file] [log] [blame]
Nguyễn Thái Ngọc Duy6fd09f52011-05-08 18:08:26 +07001#!/bin/sh
2
3test_description='magic pathspec tests using git-log'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8 test_commit initial &&
9 test_tick &&
10 git commit --allow-empty -m empty &&
11 mkdir sub
12'
13
Nguyễn Thái Ngọc Duy4db86e82013-01-21 20:00:48 +070014test_expect_success '"git log :/" should not be ambiguous' '
15 git log :/
16'
17
18test_expect_success '"git log :/a" should be ambiguous (applied both rev and worktree)' '
19 : >a &&
20 test_must_fail git log :/a 2>error &&
Vasco Almeidaab33a762016-06-17 20:21:06 +000021 test_i18ngrep ambiguous error
Nguyễn Thái Ngọc Duy6fd09f52011-05-08 18:08:26 +070022'
23
Nguyễn Thái Ngọc Duy4db86e82013-01-21 20:00:48 +070024test_expect_success '"git log :/a -- " should not be ambiguous' '
25 git log :/a --
26'
27
William Chargin6b3351e2018-07-11 22:49:09 -070028test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
29 test_when_finished "git checkout master" &&
30 git checkout --detach &&
31 # Must manually call `test_tick` instead of using `test_commit`,
32 # because the latter additionally creates a tag, which would make
33 # the commit reachable not only via HEAD.
34 test_tick &&
35 git commit --allow-empty -m detached &&
36 test_tick &&
37 git commit --allow-empty -m something-else &&
38 git log :/detached --
39'
40
41test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
42 test_must_fail git log :/detached --
43'
44
45test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' '
46 git worktree add other-tree HEAD &&
47 git -C other-tree checkout --detach &&
48 test_tick &&
49 git -C other-tree commit --allow-empty -m other-detached &&
50 git -C other-tree log :/other-detached -- &&
51 test_must_fail git log :/other-detached --
52'
53
Nguyễn Thái Ngọc Duy4db86e82013-01-21 20:00:48 +070054test_expect_success '"git log -- :/a" should not be ambiguous' '
55 git log -- :/a
56'
57
Jeff Kingbe6ed3f2017-05-26 15:06:41 -040058# This differs from the ":/a" check above in that :/in looks like a pathspec,
59# but doesn't match an actual file.
60test_expect_success '"git log :/in" should not be ambiguous' '
61 git log :/in
62'
63
Nguyễn Thái Ngọc Duy6fd09f52011-05-08 18:08:26 +070064test_expect_success '"git log :" should be ambiguous' '
65 test_must_fail git log : 2>error &&
Vasco Almeidaab33a762016-06-17 20:21:06 +000066 test_i18ngrep ambiguous error
Nguyễn Thái Ngọc Duy6fd09f52011-05-08 18:08:26 +070067'
68
69test_expect_success 'git log -- :' '
70 git log -- :
71'
72
73test_expect_success 'git log HEAD -- :/' '
74 cat >expected <<-EOF &&
75 24b24cf initial
76 EOF
77 (cd sub && git log --oneline HEAD -- :/ >../actual) &&
78 test_cmp expected actual
79'
80
Jeff King42471bc2017-05-26 15:08:39 -040081test_expect_success '"git log :^sub" is not ambiguous' '
82 git log :^sub
83'
84
85test_expect_success '"git log :^does-not-exist" does not match anything' '
86 test_must_fail git log :^does-not-exist
87'
88
89test_expect_success '"git log :!" behaves the same as :^' '
90 git log :!sub &&
91 test_must_fail git log :!does-not-exist
92'
93
Jeff Kingc99eddd2017-05-26 15:10:31 -040094test_expect_success '"git log :(exclude)sub" is not ambiguous' '
95 git log ":(exclude)sub"
96'
97
98test_expect_success '"git log :(exclude)sub --" must resolve as an object' '
99 test_must_fail git log ":(exclude)sub" --
100'
101
102test_expect_success '"git log :(unknown-magic) complains of bogus magic' '
103 test_must_fail git log ":(unknown-magic)" 2>error &&
104 test_i18ngrep pathspec.magic error
105'
106
Nguyễn Thái Ngọc Duyc8556c62013-10-19 09:41:24 +0700107test_expect_success 'command line pathspec parsing for "git log"' '
108 git reset --hard &&
109 >a &&
110 git add a &&
111 git commit -m "add an empty a" --allow-empty &&
112 echo 1 >a &&
113 git commit -a -m "update a to 1" &&
114 git checkout HEAD^ &&
115 echo 2 >a &&
116 git commit -a -m "update a to 2" &&
117 test_must_fail git merge master &&
118 git add a &&
119 git log --merge -- a
120'
121
Brandon Williamseef3df52017-12-04 16:07:34 -0800122test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
123 test_when_finished "rm -rf repo submodule" &&
124 git init submodule &&
125 test_commit -C submodule initial &&
126 git init repo &&
127 >"repo/[bracket]" &&
128 git -C repo add "[bracket]" &&
129 test_tick &&
130 git -C repo commit -m bracket &&
131 git -C repo rev-list HEAD -- "[bracket]" >expect &&
132
133 git -C repo submodule add ../submodule &&
134 test_tick &&
135 git -C repo commit -m submodule &&
136
137 git -C repo rev-list HEAD -- "[bracket]" >actual &&
138 test_cmp expect actual
139'
140
Nguyễn Thái Ngọc Duy6fd09f52011-05-08 18:08:26 +0700141test_done