git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] merge-base: add tests for --is-ancestor

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 29, 2026, 09:39 UTC
Message-ID
<9a47d529-6195-435b-90a6-e511856f128e@gmail.com>
In-Reply-To
<pull.2186.git.1784998828879.gitgitgadget@gmail.com>
Hi Nikolaus
On 25/07/2026 18:00, Nikolaus Schuetz via GitGitGadget wrote:
Show 7 quoted lines
> 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.
Thanks for adding some tests for this option
Show 18 quoted lines
> 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
> +	)
> +'

Do we really need to create a new repository? None of the existing tests do that - can't we just use the commits created by the first test? Having said that, the tests below look good. We could perhaps have a test to check that it fails with one commit or three commits but what you have here is clearly a very useful improvement in our test coverage.

Thanks
Phillip
Show 26 quoted lines
> +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
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 6 in “merge-base: add tests for --is-ancestor”
  1. merge-base: add tests for --is-ancestorNikolaus Schuetz via GitGitGadget, Jul 25, 2026
  2. Junio C HamanoJul 28, 2026
  3. Phillip WoodJul 29, 2026
  4. Junio C HamanoJul 29, 2026
  5. merge-base: add tests for --is-ancestorNikolaus Schuetz via GitGitGadget, Jul 30, 2026
  6. Junio C HamanoJul 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.