Commit
89454a60ed3c668aabdc372327207096c9613e56
merge-base: add tests for --is-ancestor
`git merge-base --is-ancestor A B` is used a lot in scripts but has no tests. Add some to t6010 covering its exit codes: 0 when A is an ancestor of B, 1 when it is not, and 128 (not 1) when given a bad argument. Also check that --is-ancestor and --all can't be combined, and that the resulting error names both options. Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nikolaus Schuetz <nikolauspschuetz@gmail.com> · 2026-07-30 06:19 UTC · committed by Junio C Hamano
1 file changed,
+31
−0
modified t/t6010-merge-base.sh
| @@ -305,4 +305,35 @@ test_expect_success 'merge-base --octopus --all for complex tree' ' | |||
| 305 | 305 | test_cmp expected actual | |
| 306 | 306 | ' | |
| 307 | 307 | ||
| 308 | + | test_expect_success '--is-ancestor with an ancestor and a descendant' ' | |
| 309 | + | git merge-base --is-ancestor $E $A && | |
| 310 | + | test_expect_code 1 git merge-base --is-ancestor $A $E | |
| 311 | + | ' | |
| 312 | + | ||
| 313 | + | test_expect_success '--is-ancestor treats a commit as its own ancestor' ' | |
| 314 | + | git merge-base --is-ancestor $A $A | |
| 315 | + | ' | |
| 316 | + | ||
| 317 | + | test_expect_success '--is-ancestor with diverged commits' ' | |
| 318 | + | test_expect_code 1 git merge-base --is-ancestor $G $H && | |
| 319 | + | test_expect_code 1 git merge-base --is-ancestor $H $G | |
| 320 | + | ' | |
| 321 | + | ||
| 322 | + | test_expect_success '--is-ancestor exits 128 on a bad commit' ' | |
| 323 | + | test_expect_code 128 git merge-base --is-ancestor $A no-such-commit && | |
| 324 | + | test_expect_code 128 git merge-base --is-ancestor no-such-commit $A | |
| 325 | + | ' | |
| 326 | + | ||
| 327 | + | test_expect_success '--is-ancestor requires exactly two commits' ' | |
| 328 | + | test_expect_code 129 git merge-base --is-ancestor && | |
| 329 | + | test_expect_code 129 git merge-base --is-ancestor $A && | |
| 330 | + | test_expect_code 128 git merge-base --is-ancestor $E $A $B 2>err && | |
| 331 | + | test_grep ".--is-ancestor takes exactly two commits" err | |
| 332 | + | ' | |
| 333 | + | ||
| 334 | + | test_expect_success '--is-ancestor and --all cannot be used together' ' | |
| 335 | + | test_expect_code 128 git merge-base --is-ancestor --all $E $A 2>err && | |
| 336 | + | test_grep "options .--is-ancestor. and .--all. cannot be used together" err | |
| 337 | + | ' | |
| 338 | + | ||
| 308 | 339 | test_done | |