* [PATCH] merge-base: add tests for --is-ancestor
@ 2026-07-25 17:00 Nikolaus Schuetz via GitGitGadget
0 siblings, 0 replies; only message in thread
From: Nikolaus Schuetz via GitGitGadget @ 2026-07-25 17:00 UTC (permalink / raw)
To: git; +Cc: Nikolaus Schuetz, Nikolaus Schuetz
From: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
`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>
---
merge-base: add tests for --is-ancestor
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2186%2Fnikolauspschuetz%2Ft6010-test-is-ancestor-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2186
t/t6010-merge-base.sh | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh
index 44c726ea39..d28d9dab2c 100755
--- a/t/t6010-merge-base.sh
+++ b/t/t6010-merge-base.sh
@@ -305,4 +305,38 @@ test_expect_success 'merge-base --octopus --all for complex tree' '
test_cmp expected actual
'
+test_expect_success 'setup --is-ancestor' '
+ git init is-ancestor &&
+ (
+ cd is-ancestor &&
+ test_commit one &&
+ test_commit two &&
+ git checkout -b side one &&
+ test_commit three
+ )
+'
+
+test_expect_success '--is-ancestor parent and child' '
+ git -C is-ancestor merge-base --is-ancestor one two &&
+ test_expect_code 1 git -C is-ancestor merge-base --is-ancestor two one
+'
+
+test_expect_success '--is-ancestor self' '
+ git -C is-ancestor merge-base --is-ancestor two two
+'
+
+test_expect_success '--is-ancestor diverged commits' '
+ test_expect_code 1 git -C is-ancestor merge-base --is-ancestor three two
+'
+
+test_expect_success '--is-ancestor exit 128 non-existent commit' '
+ test_expect_code 128 git -C is-ancestor merge-base --is-ancestor one no-such-commit &&
+ test_expect_code 128 git -C is-ancestor merge-base --is-ancestor no-such-commit one
+'
+
+test_expect_success '--is-ancestor and --all cannot be used together' '
+ test_expect_code 128 git -C is-ancestor merge-base --is-ancestor --all one two 2>err &&
+ test_grep "options .--is-ancestor. and .--all. cannot be used together" err
+'
+
test_done
base-commit: f60db8d575adb79761d363e026fb49bddf330c73
--
gitgitgadget
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-25 17:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25 17:00 [PATCH] merge-base: add tests for --is-ancestor Nikolaus Schuetz via GitGitGadget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox