]>
Commit | Line | Data |
---|---|---|
5312ab11 JH |
1 | #!/bin/sh |
2 | ||
d91ce887 SG |
3 | test_description='test describe' |
4 | ||
5 | # o---o-----o----o----o-------o----x | |
6 | # \ D,R e / | |
7 | # \---o-------------o-' | |
8 | # \ B / | |
9 | # `-o----o----o-' | |
10 | # A c | |
11 | # | |
12 | # First parent of a merge commit is on the same line, second parent below. | |
13 | ||
1550bb6e | 14 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
15 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
16 | ||
5312ab11 JH |
17 | . ./test-lib.sh |
18 | ||
19 | check_describe () { | |
64568c71 ÆAB |
20 | indir= && |
21 | while test $# != 0 | |
22 | do | |
23 | case "$1" in | |
24 | -C) | |
25 | indir="$2" | |
26 | shift | |
27 | ;; | |
28 | *) | |
29 | break | |
30 | ;; | |
31 | esac | |
32 | shift | |
33 | done && | |
34 | indir=${indir:+"$indir"/} && | |
5312ab11 JH |
35 | expect="$1" |
36 | shift | |
c593a263 SG |
37 | describe_opts="$@" |
38 | test_expect_success "describe $describe_opts" ' | |
64568c71 | 39 | git ${indir:+ -C "$indir"} describe $describe_opts >raw && |
a46a8482 ÆAB |
40 | sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual && |
41 | echo "$expect" >expect && | |
42 | test_cmp expect actual | |
5312ab11 JH |
43 | ' |
44 | } | |
45 | ||
46 | test_expect_success setup ' | |
8cfe386b ÆAB |
47 | test_commit initial file one && |
48 | test_commit second file two && | |
49 | test_commit third file three && | |
50 | test_commit --annotate A file A && | |
51 | test_commit c file c && | |
5312ab11 | 52 | |
8cfe386b ÆAB |
53 | git reset --hard second && |
54 | test_commit --annotate B side B && | |
5312ab11 JH |
55 | |
56 | test_tick && | |
3604e7c5 | 57 | git merge -m Merged c && |
5be60078 | 58 | merged=$(git rev-parse HEAD) && |
5312ab11 | 59 | |
8cfe386b ÆAB |
60 | git reset --hard second && |
61 | test_commit --no-tag D another D && | |
5312ab11 JH |
62 | |
63 | test_tick && | |
8cfe386b | 64 | git tag -a -m R R && |
5312ab11 | 65 | |
8cfe386b ÆAB |
66 | test_commit e another DD && |
67 | test_commit --no-tag "yet another" another DDD && | |
5312ab11 JH |
68 | |
69 | test_tick && | |
3604e7c5 | 70 | git merge -m Merged $merged && |
5312ab11 | 71 | |
8cfe386b | 72 | test_commit --no-tag x file |
5312ab11 JH |
73 | ' |
74 | ||
a46a8482 ÆAB |
75 | check_describe A-8-gHASH HEAD |
76 | check_describe A-7-gHASH HEAD^ | |
77 | check_describe R-2-gHASH HEAD^^ | |
78 | check_describe A-3-gHASH HEAD^^2 | |
5312ab11 | 79 | check_describe B HEAD^^2^ |
a46a8482 | 80 | check_describe R-1-gHASH HEAD^^^ |
5312ab11 | 81 | |
a46a8482 ÆAB |
82 | check_describe c-7-gHASH --tags HEAD |
83 | check_describe c-6-gHASH --tags HEAD^ | |
84 | check_describe e-1-gHASH --tags HEAD^^ | |
85 | check_describe c-2-gHASH --tags HEAD^^2 | |
5312ab11 | 86 | check_describe B --tags HEAD^^2^ |
7a0d61bb | 87 | check_describe e --tags HEAD^^^ |
c95ae3ff | 88 | check_describe e --tags --exact-match HEAD^^^ |
7a0d61bb | 89 | |
1550bb6e | 90 | check_describe heads/main --all HEAD |
a46a8482 | 91 | check_describe tags/c-6-gHASH --all HEAD^ |
7a0d61bb | 92 | check_describe tags/e --all HEAD^^^ |
5312ab11 | 93 | |
a46a8482 ÆAB |
94 | check_describe B-0-gHASH --long HEAD^^2^ |
95 | check_describe A-3-gHASH --long HEAD^^2 | |
518120e3 | 96 | |
a46a8482 ÆAB |
97 | check_describe c-7-gHASH --tags |
98 | check_describe e-3-gHASH --first-parent --tags | |
e00dd1e9 | 99 | |
c95ae3ff RS |
100 | check_describe c-7-gHASH --tags --no-exact-match HEAD |
101 | check_describe e-3-gHASH --first-parent --tags --no-exact-match HEAD | |
102 | ||
103 | test_expect_success '--exact-match failure' ' | |
104 | test_must_fail git describe --exact-match HEAD 2>err | |
105 | ' | |
106 | ||
2bd07065 SG |
107 | test_expect_success 'describe --contains defaults to HEAD without commit-ish' ' |
108 | echo "A^0" >expect && | |
109 | git checkout A && | |
110 | test_when_finished "git checkout -" && | |
111 | git describe --contains >actual && | |
112 | test_cmp expect actual | |
113 | ' | |
114 | ||
1bba0013 | 115 | check_describe tags/A --all A^0 |
81dc223d | 116 | |
7f07c1cd | 117 | test_expect_success 'renaming tag A to Q locally produces a warning' " |
e46775cf HWN |
118 | git update-ref refs/tags/Q $(git rev-parse refs/tags/A) && |
119 | git update-ref -d refs/tags/A && | |
7f07c1cd ÆAB |
120 | git describe HEAD 2>err >out && |
121 | cat >expected <<-\EOF && | |
122 | warning: tag 'Q' is externally known as 'A' | |
123 | EOF | |
124 | test_cmp expected err && | |
125 | grep -E '^A-8-g[0-9a-f]+$' out | |
126 | " | |
127 | ||
ff165f00 JH |
128 | test_expect_success 'misnamed annotated tag forces long output' ' |
129 | description=$(git describe --no-long Q^0) && | |
130 | expr "$description" : "A-0-g[0-9a-f]*$" && | |
131 | git rev-parse --verify "$description" >actual && | |
132 | git rev-parse --verify Q^0 >expect && | |
133 | test_cmp expect actual | |
134 | ' | |
135 | ||
136 | test_expect_success 'abbrev=0 will not break misplaced tag (1)' ' | |
137 | description=$(git describe --abbrev=0 Q^0) && | |
138 | expr "$description" : "A-0-g[0-9a-f]*$" | |
139 | ' | |
140 | ||
141 | test_expect_success 'abbrev=0 will not break misplaced tag (2)' ' | |
142 | description=$(git describe --abbrev=0 c^0) && | |
143 | expr "$description" : "A-1-g[0-9a-f]*$" | |
144 | ' | |
145 | ||
3291fe40 | 146 | test_expect_success 'rename tag Q back to A' ' |
e46775cf HWN |
147 | git update-ref refs/tags/A $(git rev-parse refs/tags/Q) && |
148 | git update-ref -d refs/tags/Q | |
3291fe40 SP |
149 | ' |
150 | ||
d1b28f51 | 151 | test_expect_success 'pack tag refs' 'git pack-refs' |
a46a8482 | 152 | check_describe A-8-gHASH HEAD |
d1b28f51 | 153 | |
c801170b SS |
154 | test_expect_success 'describe works from outside repo using --git-dir' ' |
155 | git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" && | |
156 | git --git-dir "$TRASH_DIRECTORY/bare" describe >out && | |
a46a8482 | 157 | grep -E "^A-8-g[0-9a-f]+$" out |
c801170b SS |
158 | ' |
159 | ||
a46a8482 | 160 | check_describe "A-8-gHASH" --dirty |
9f67d2e8 | 161 | |
2ed5c8e1 SS |
162 | test_expect_success 'describe --dirty with --work-tree' ' |
163 | ( | |
164 | cd "$TEST_DIRECTORY" && | |
165 | git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out" | |
166 | ) && | |
a46a8482 | 167 | grep -E "^A-8-g[0-9a-f]+$" out |
2ed5c8e1 SS |
168 | ' |
169 | ||
9f67d2e8 JP |
170 | test_expect_success 'set-up dirty work tree' ' |
171 | echo >>file | |
172 | ' | |
173 | ||
2ed5c8e1 | 174 | test_expect_success 'describe --dirty with --work-tree (dirty)' ' |
2df546e1 | 175 | git describe --dirty >expected && |
2ed5c8e1 SS |
176 | ( |
177 | cd "$TEST_DIRECTORY" && | |
178 | git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out" | |
179 | ) && | |
a46a8482 | 180 | grep -E "^A-8-g[0-9a-f]+-dirty$" out && |
2df546e1 | 181 | test_cmp expected out |
2ed5c8e1 SS |
182 | ' |
183 | ||
2ed5c8e1 | 184 | test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' ' |
2df546e1 | 185 | git describe --dirty=.mod >expected && |
2ed5c8e1 SS |
186 | ( |
187 | cd "$TEST_DIRECTORY" && | |
188 | git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out" | |
189 | ) && | |
a46a8482 | 190 | grep -E "^A-8-g[0-9a-f]+.mod$" out && |
2df546e1 | 191 | test_cmp expected out |
2ed5c8e1 SS |
192 | ' |
193 | ||
9f67d2e8 JP |
194 | test_expect_success 'describe --dirty HEAD' ' |
195 | test_must_fail git describe --dirty HEAD | |
196 | ' | |
197 | ||
4ed19a3c MD |
198 | test_expect_success 'set-up matching pattern tests' ' |
199 | git tag -a -m test-annotated test-annotated && | |
200 | echo >>file && | |
201 | test_tick && | |
202 | git commit -a -m "one more" && | |
203 | git tag test1-lightweight && | |
204 | echo >>file && | |
205 | test_tick && | |
206 | git commit -a -m "yet another" && | |
207 | git tag test2-lightweight && | |
208 | echo >>file && | |
209 | test_tick && | |
210 | git commit -a -m "even more" | |
211 | ||
212 | ' | |
213 | ||
a46a8482 | 214 | check_describe "test-annotated-3-gHASH" --match="test-*" |
4ed19a3c | 215 | |
a46a8482 | 216 | check_describe "test1-lightweight-2-gHASH" --tags --match="test1-*" |
4ed19a3c | 217 | |
a46a8482 | 218 | check_describe "test2-lightweight-1-gHASH" --tags --match="test2-*" |
4ed19a3c | 219 | |
a46a8482 | 220 | check_describe "test2-lightweight-0-gHASH" --long --tags --match="test2-*" HEAD^ |
14d4642e | 221 | |
a46a8482 | 222 | check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --match="test2-*" HEAD^ |
43f8080e | 223 | |
a46a8482 | 224 | check_describe "test2-lightweight-0-gHASH" --long --tags --match="test1-*" --no-match --match="test2-*" HEAD^ |
43f8080e | 225 | |
a46a8482 | 226 | check_describe "test1-lightweight-2-gHASH" --long --tags --match="test1-*" --match="test3-*" HEAD |
da769d29 | 227 | |
a46a8482 | 228 | check_describe "test1-lightweight-2-gHASH" --long --tags --match="test3-*" --match="test1-*" HEAD |
da769d29 | 229 | |
6d68b2ab MK |
230 | test_expect_success 'set-up branches' ' |
231 | git branch branch_A A && | |
232 | git branch branch_C c && | |
233 | git update-ref refs/remotes/origin/remote_branch_A "A^{commit}" && | |
234 | git update-ref refs/remotes/origin/remote_branch_C "c^{commit}" && | |
235 | git update-ref refs/original/original_branch_A test-annotated~2 | |
236 | ' | |
237 | ||
a46a8482 | 238 | check_describe "heads/branch_A-11-gHASH" --all --match="branch_*" --exclude="branch_C" HEAD |
6d68b2ab | 239 | |
a46a8482 | 240 | check_describe "remotes/origin/remote_branch_A-11-gHASH" --all --match="origin/remote_branch_*" --exclude="origin/remote_branch_C" HEAD |
6d68b2ab | 241 | |
a46a8482 | 242 | check_describe "original/original_branch_A-6-gHASH" --all test-annotated~1 |
6d68b2ab MK |
243 | |
244 | test_expect_success '--match does not work for other types' ' | |
245 | test_must_fail git describe --all --match="*original_branch_*" test-annotated~1 | |
246 | ' | |
247 | ||
248 | test_expect_success '--exclude does not work for other types' ' | |
249 | R=$(git describe --all --exclude="any_pattern_even_not_matching" test-annotated~1) && | |
250 | case "$R" in | |
251 | *original_branch_A*) echo "fail: Found unknown reference $R with --exclude" | |
252 | false;; | |
253 | *) echo ok: Found some known type;; | |
254 | esac | |
255 | ' | |
256 | ||
118aa4ac JH |
257 | test_expect_success 'name-rev with exact tags' ' |
258 | echo A >expect && | |
259 | tag_object=$(git rev-parse refs/tags/A) && | |
260 | git name-rev --tags --name-only $tag_object >actual && | |
261 | test_cmp expect actual && | |
262 | ||
263 | echo "A^0" >expect && | |
264 | tagged_commit=$(git rev-parse "refs/tags/A^0") && | |
265 | git name-rev --tags --name-only $tagged_commit >actual && | |
266 | test_cmp expect actual | |
267 | ' | |
268 | ||
a24fa652 MG |
269 | test_expect_success 'name-rev --all' ' |
270 | >expect.unsorted && | |
271 | for rev in $(git rev-list --all) | |
272 | do | |
0c51d6b4 | 273 | git name-rev $rev >>expect.unsorted || return 1 |
a24fa652 MG |
274 | done && |
275 | sort <expect.unsorted >expect && | |
276 | git name-rev --all >actual.unsorted && | |
277 | sort <actual.unsorted >actual && | |
278 | test_cmp expect actual | |
279 | ' | |
280 | ||
34ae3b70 | 281 | test_expect_success 'name-rev --annotate-stdin' ' |
a24fa652 MG |
282 | >expect.unsorted && |
283 | for rev in $(git rev-list --all) | |
284 | do | |
285 | name=$(git name-rev --name-only $rev) && | |
0c51d6b4 | 286 | echo "$rev ($name)" >>expect.unsorted || return 1 |
a24fa652 MG |
287 | done && |
288 | sort <expect.unsorted >expect && | |
34ae3b70 | 289 | git rev-list --all | git name-rev --annotate-stdin >actual.unsorted && |
a24fa652 MG |
290 | sort <actual.unsorted >actual && |
291 | test_cmp expect actual | |
292 | ' | |
293 | ||
34ae3b70 JC |
294 | test_expect_success 'name-rev --stdin deprecated' " |
295 | git rev-list --all | git name-rev --stdin 2>actual && | |
296 | grep -E 'warning: --stdin is deprecated' actual | |
297 | " | |
298 | ||
adfc1857 JH |
299 | test_expect_success 'describe --contains with the exact tags' ' |
300 | echo "A^0" >expect && | |
301 | tag_object=$(git rev-parse refs/tags/A) && | |
302 | git describe --contains $tag_object >actual && | |
303 | test_cmp expect actual && | |
304 | ||
305 | echo "A^0" >expect && | |
306 | tagged_commit=$(git rev-parse "refs/tags/A^0") && | |
307 | git describe --contains $tagged_commit >actual && | |
308 | test_cmp expect actual | |
309 | ' | |
310 | ||
43f8080e JK |
311 | test_expect_success 'describe --contains and --match' ' |
312 | echo "A^0" >expect && | |
313 | tagged_commit=$(git rev-parse "refs/tags/A^0") && | |
314 | test_must_fail git describe --contains --match="B" $tagged_commit && | |
315 | git describe --contains --match="B" --match="A" $tagged_commit >actual && | |
316 | test_cmp expect actual | |
317 | ' | |
318 | ||
77d21f29 JK |
319 | test_expect_success 'describe --exclude' ' |
320 | echo "c~1" >expect && | |
321 | tagged_commit=$(git rev-parse "refs/tags/A^0") && | |
322 | test_must_fail git describe --contains --match="B" $tagged_commit && | |
323 | git describe --contains --match="?" --exclude="A" $tagged_commit >actual && | |
324 | test_cmp expect actual | |
325 | ' | |
326 | ||
43f8080e JK |
327 | test_expect_success 'describe --contains and --no-match' ' |
328 | echo "A^0" >expect && | |
329 | tagged_commit=$(git rev-parse "refs/tags/A^0") && | |
330 | git describe --contains --match="B" --no-match $tagged_commit >actual && | |
331 | test_cmp expect actual | |
332 | ' | |
333 | ||
b0176ce6 SB |
334 | test_expect_success 'setup and absorb a submodule' ' |
335 | test_create_repo sub1 && | |
336 | test_commit -C sub1 initial && | |
337 | git submodule add ./sub1 && | |
338 | git submodule absorbgitdirs && | |
339 | git commit -a -m "add submodule" && | |
340 | git describe --dirty >expect && | |
341 | git describe --broken >out && | |
342 | test_cmp expect out | |
343 | ' | |
344 | ||
64127575 | 345 | test_expect_success 'describe chokes on severely broken submodules' ' |
b0176ce6 SB |
346 | mv .git/modules/sub1/ .git/modules/sub_moved && |
347 | test_must_fail git describe --dirty | |
348 | ' | |
2ed5c8e1 | 349 | |
2deda007 | 350 | test_expect_success 'describe ignoring a broken submodule' ' |
b0176ce6 | 351 | git describe --broken >out && |
2ed5c8e1 SS |
352 | grep broken out |
353 | ' | |
354 | ||
355 | test_expect_success 'describe with --work-tree ignoring a broken submodule' ' | |
356 | ( | |
357 | cd "$TEST_DIRECTORY" && | |
358 | git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out" | |
359 | ) && | |
ac9b2401 | 360 | test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" && |
b0176ce6 SB |
361 | grep broken out |
362 | ' | |
363 | ||
644eb60b SB |
364 | test_expect_success 'describe a blob at a directly tagged commit' ' |
365 | echo "make it a unique blob" >file && | |
366 | git add file && git commit -m "content in file" && | |
367 | git tag -a -m "latest annotated tag" unique-file && | |
368 | git describe HEAD:file >actual && | |
369 | echo "unique-file:file" >expect && | |
370 | test_cmp expect actual | |
371 | ' | |
372 | ||
373 | test_expect_success 'describe a blob with its first introduction' ' | |
374 | git commit --allow-empty -m "empty commit" && | |
375 | git rm file && | |
376 | git commit -m "delete blob" && | |
377 | git revert HEAD && | |
378 | git commit --allow-empty -m "empty commit" && | |
379 | git describe HEAD:file >actual && | |
380 | echo "unique-file:file" >expect && | |
381 | test_cmp expect actual | |
382 | ' | |
383 | ||
384 | test_expect_success 'describe directly tagged blob' ' | |
385 | git tag test-blob unique-file:file && | |
386 | git describe test-blob >actual && | |
387 | echo "unique-file:file" >expect && | |
388 | # suboptimal: we rather want to see "test-blob" | |
389 | test_cmp expect actual | |
390 | ' | |
391 | ||
392 | test_expect_success 'describe tag object' ' | |
393 | git tag test-blob-1 -a -m msg unique-file:file && | |
394 | test_must_fail git describe test-blob-1 2>actual && | |
6789275d | 395 | test_grep "fatal: test-blob-1 is neither a commit nor blob" actual |
644eb60b SB |
396 | ' |
397 | ||
49f7a2fd | 398 | test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' ' |
31625b34 MG |
399 | i=1 && |
400 | while test $i -lt 8000 | |
401 | do | |
1550bb6e | 402 | echo "commit refs/heads/main |
31625b34 MG |
403 | committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 |
404 | data <<EOF | |
405 | commit #$i | |
74d2f569 ES |
406 | EOF" && |
407 | if test $i = 1 | |
408 | then | |
409 | echo "from refs/heads/main^0" | |
410 | fi && | |
0c51d6b4 | 411 | i=$(($i + 1)) || return 1 |
31625b34 | 412 | done | git fast-import && |
1550bb6e | 413 | git checkout main && |
31625b34 MG |
414 | git tag far-far-away HEAD^ && |
415 | echo "HEAD~4000 tags/far-far-away~3999" >expect && | |
416 | git name-rev HEAD~4000 >actual && | |
417 | test_cmp expect actual && | |
418 | run_with_limited_stack git name-rev HEAD~4000 >actual && | |
419 | test_cmp expect actual | |
420 | ' | |
421 | ||
422 | test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' ' | |
423 | git tag -f far-far-away HEAD~7999 && | |
424 | echo "far-far-away" >expect && | |
425 | git describe --tags --abbrev=0 HEAD~4000 >actual && | |
426 | test_cmp expect actual && | |
427 | run_with_limited_stack git describe --tags --abbrev=0 HEAD~4000 >actual && | |
428 | test_cmp expect actual | |
429 | ' | |
430 | ||
1bba0013 DKF |
431 | check_describe tags/A --all A |
432 | check_describe tags/c --all c | |
433 | check_describe heads/branch_A --all --match='branch_*' branch_A | |
434 | ||
a8e7a2bf JK |
435 | test_expect_success 'describe complains about tree object' ' |
436 | test_must_fail git describe HEAD^{tree} | |
437 | ' | |
438 | ||
439 | test_expect_success 'describe complains about missing object' ' | |
8125a58b | 440 | test_must_fail git describe $ZERO_OID |
a8e7a2bf JK |
441 | ' |
442 | ||
2e09c012 | 443 | test_expect_success 'name-rev a rev shortly after epoch' ' |
1550bb6e | 444 | test_when_finished "git checkout main" && |
2e09c012 SG |
445 | |
446 | git checkout --orphan no-timestamp-underflow && | |
447 | # Any date closer to epoch than the CUTOFF_DATE_SLOP constant | |
448 | # in builtin/name-rev.c. | |
449 | GIT_COMMITTER_DATE="@1234 +0000" \ | |
450 | git commit -m "committer date shortly after epoch" && | |
451 | old_commit_oid=$(git rev-parse HEAD) && | |
452 | ||
453 | echo "$old_commit_oid no-timestamp-underflow" >expect && | |
454 | git name-rev $old_commit_oid >actual && | |
455 | test_cmp expect actual | |
456 | ' | |
457 | ||
1550bb6e | 458 | # A--------------main |
d59fc836 SG |
459 | # \ / |
460 | # \----------M2 | |
461 | # \ / | |
462 | # \---M1-C | |
463 | # \ / | |
464 | # B | |
465 | test_expect_success 'name-rev covers all conditions while looking at parents' ' | |
466 | git init repo && | |
467 | ( | |
468 | cd repo && | |
469 | ||
470 | echo A >file && | |
471 | git add file && | |
472 | git commit -m A && | |
473 | A=$(git rev-parse HEAD) && | |
474 | ||
475 | git checkout --detach && | |
476 | echo B >file && | |
477 | git commit -m B file && | |
478 | B=$(git rev-parse HEAD) && | |
479 | ||
480 | git checkout $A && | |
481 | git merge --no-ff $B && # M1 | |
482 | ||
483 | echo C >file && | |
484 | git commit -m C file && | |
485 | ||
486 | git checkout $A && | |
487 | git merge --no-ff HEAD@{1} && # M2 | |
488 | ||
1550bb6e | 489 | git checkout main && |
d59fc836 SG |
490 | git merge --no-ff HEAD@{1} && |
491 | ||
1550bb6e | 492 | echo "$B main^2^2~1^2" >expect && |
d59fc836 SG |
493 | git name-rev $B >actual && |
494 | ||
495 | test_cmp expect actual | |
496 | ) | |
497 | ' | |
498 | ||
2e8ea40f JK |
499 | # A-B-C-D-E-main |
500 | # | |
501 | # Where C has a non-monotonically increasing commit timestamp w.r.t. other | |
502 | # commits | |
503 | test_expect_success 'non-monotonic commit dates setup' ' | |
504 | UNIX_EPOCH_ZERO="@0 +0000" && | |
505 | git init non-monotonic && | |
506 | test_commit -C non-monotonic A && | |
507 | test_commit -C non-monotonic --no-tag B && | |
508 | test_commit -C non-monotonic --no-tag --date "$UNIX_EPOCH_ZERO" C && | |
509 | test_commit -C non-monotonic D && | |
510 | test_commit -C non-monotonic E | |
511 | ' | |
512 | ||
513 | test_expect_success 'name-rev with commitGraph handles non-monotonic timestamps' ' | |
514 | test_config -C non-monotonic core.commitGraph true && | |
515 | ( | |
516 | cd non-monotonic && | |
517 | ||
518 | git commit-graph write --reachable && | |
519 | ||
520 | echo "main~3 tags/D~2" >expect && | |
521 | git name-rev --tags main~3 >actual && | |
522 | ||
523 | test_cmp expect actual | |
524 | ) | |
525 | ' | |
526 | ||
527 | test_expect_success 'name-rev --all works with non-monotonic timestamps' ' | |
528 | test_config -C non-monotonic core.commitGraph false && | |
529 | ( | |
530 | cd non-monotonic && | |
531 | ||
532 | rm -rf .git/info/commit-graph* && | |
533 | ||
534 | cat >tags <<-\EOF && | |
535 | tags/E | |
536 | tags/D | |
537 | tags/D~1 | |
538 | tags/D~2 | |
539 | tags/A | |
540 | EOF | |
541 | ||
542 | git log --pretty=%H >revs && | |
543 | ||
544 | paste -d" " revs tags | sort >expect && | |
545 | ||
546 | git name-rev --tags --all | sort >actual && | |
547 | test_cmp expect actual | |
548 | ) | |
549 | ' | |
550 | ||
551 | test_expect_success 'name-rev --annotate-stdin works with non-monotonic timestamps' ' | |
552 | test_config -C non-monotonic core.commitGraph false && | |
553 | ( | |
554 | cd non-monotonic && | |
555 | ||
556 | rm -rf .git/info/commit-graph* && | |
557 | ||
558 | cat >expect <<-\EOF && | |
559 | E | |
560 | D | |
561 | D~1 | |
562 | D~2 | |
563 | A | |
564 | EOF | |
565 | ||
566 | git log --pretty=%H >revs && | |
567 | git name-rev --tags --annotate-stdin --name-only <revs >actual && | |
568 | test_cmp expect actual | |
569 | ) | |
570 | ' | |
571 | ||
572 | test_expect_success 'name-rev --all works with commitGraph' ' | |
573 | test_config -C non-monotonic core.commitGraph true && | |
574 | ( | |
575 | cd non-monotonic && | |
576 | ||
577 | git commit-graph write --reachable && | |
578 | ||
579 | cat >tags <<-\EOF && | |
580 | tags/E | |
581 | tags/D | |
582 | tags/D~1 | |
583 | tags/D~2 | |
584 | tags/A | |
585 | EOF | |
586 | ||
587 | git log --pretty=%H >revs && | |
588 | ||
589 | paste -d" " revs tags | sort >expect && | |
590 | ||
591 | git name-rev --tags --all | sort >actual && | |
592 | test_cmp expect actual | |
593 | ) | |
594 | ' | |
595 | ||
596 | test_expect_success 'name-rev --annotate-stdin works with commitGraph' ' | |
597 | test_config -C non-monotonic core.commitGraph true && | |
598 | ( | |
599 | cd non-monotonic && | |
600 | ||
601 | git commit-graph write --reachable && | |
602 | ||
603 | cat >expect <<-\EOF && | |
604 | E | |
605 | D | |
606 | D~1 | |
607 | D~2 | |
608 | A | |
609 | EOF | |
610 | ||
611 | git log --pretty=%H >revs && | |
612 | git name-rev --tags --annotate-stdin --name-only <revs >actual && | |
613 | test_cmp expect actual | |
614 | ) | |
615 | ' | |
616 | ||
30b1c7ad BE |
617 | # B |
618 | # o | |
619 | # \ | |
620 | # o-----o---o----x | |
621 | # A | |
622 | # | |
33b4ae11 | 623 | test_expect_success 'setup: describe commits with disjoint bases' ' |
30b1c7ad BE |
624 | git init disjoint1 && |
625 | ( | |
626 | cd disjoint1 && | |
627 | ||
628 | echo o >> file && git add file && git commit -m o && | |
629 | echo A >> file && git add file && git commit -m A && | |
630 | git tag A -a -m A && | |
631 | echo o >> file && git add file && git commit -m o && | |
632 | ||
633 | git checkout --orphan branch && rm file && | |
634 | echo B > file2 && git add file2 && git commit -m B && | |
635 | git tag B -a -m B && | |
33b4ae11 | 636 | git merge --no-ff --allow-unrelated-histories main -m x |
30b1c7ad BE |
637 | ) |
638 | ' | |
639 | ||
64568c71 | 640 | check_describe -C disjoint1 "A-3-gHASH" HEAD |
33b4ae11 | 641 | |
30b1c7ad BE |
642 | # B |
643 | # o---o---o------------. | |
644 | # \ | |
645 | # o---o---x | |
646 | # A | |
647 | # | |
33b4ae11 | 648 | test_expect_success 'setup: describe commits with disjoint bases 2' ' |
30b1c7ad BE |
649 | git init disjoint2 && |
650 | ( | |
651 | cd disjoint2 && | |
652 | ||
653 | echo A >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:00" git commit -m A && | |
654 | git tag A -a -m A && | |
655 | echo o >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:01" git commit -m o && | |
656 | ||
657 | git checkout --orphan branch && | |
658 | echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o && | |
659 | echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o && | |
660 | echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B && | |
661 | git tag B -a -m B && | |
33b4ae11 | 662 | git merge --no-ff --allow-unrelated-histories main -m x |
30b1c7ad BE |
663 | ) |
664 | ' | |
665 | ||
64568c71 | 666 | check_describe -C disjoint2 "B-3-gHASH" HEAD |
33b4ae11 | 667 | |
b2182a87 EN |
668 | test_expect_success 'setup misleading taggerdates' ' |
669 | GIT_COMMITTER_DATE="2006-12-12 12:31" git tag -a -m "another tag" newer-tag-older-commit unique-file~1 | |
670 | ' | |
671 | ||
672 | check_describe newer-tag-older-commit~1 --contains unique-file~2 | |
673 | ||
5312ab11 | 674 | test_done |