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