Skip to content

merge-base: add tests for --is-ancestor - #2186

Open
nikolauspschuetz wants to merge 1 commit into
gitgitgadget:masterfrom
nikolauspschuetz:t6010-test-is-ancestor
Open

merge-base: add tests for --is-ancestor#2186
nikolauspschuetz wants to merge 1 commit into
gitgitgadget:masterfrom
nikolauspschuetz:t6010-test-is-ancestor

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Jul 25, 2026

Copy link
Copy Markdown

Changes since v1, per review:

  • Reuse the E---D---C---B---A history and the G/H merges from the
    "set up G and H" test instead of creating a separate repository.
  • Add a test that --is-ancestor requires exactly two commits: too few
    is a usage error (exit 129), while more than two is rejected with
    "--is-ancestor takes exactly two commits" (exit 128).

cc: Phillip Wood phillip.wood123@gmail.com

@gitgitgadget

gitgitgadget Bot commented Jul 25, 2026

Copy link
Copy Markdown

Welcome to GitGitGadget

Hi @nikolauspschuetz, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@nikolauspschuetz nikolauspschuetz changed the title merge-base: add tests for --is-ancestor t6010: add tests for --is-ancestor Jul 25, 2026
@nikolauspschuetz nikolauspschuetz changed the title t6010: add tests for --is-ancestor t6010: add tests for merge-base --is-ancestor Jul 25, 2026
@nikolauspschuetz

Copy link
Copy Markdown
Author

/preview

@gitgitgadget

gitgitgadget Bot commented Jul 25, 2026

Copy link
Copy Markdown

Error: User nikolauspschuetz is not yet permitted to use GitGitGadget

@Ikke

Ikke commented Jul 25, 2026

Copy link
Copy Markdown

/allow

@gitgitgadget

gitgitgadget Bot commented Jul 25, 2026

Copy link
Copy Markdown

User nikolauspschuetz is now allowed to use GitGitGadget.

@nikolauspschuetz

Copy link
Copy Markdown
Author

/preview

@gitgitgadget

gitgitgadget Bot commented Jul 25, 2026

Copy link
Copy Markdown

Preview email sent as pull.2186.git.1784958204570.gitgitgadget@gmail.com

@nikolauspschuetz nikolauspschuetz changed the title t6010: add tests for merge-base --is-ancestor merge-base: add tests for --is-ancestor Jul 25, 2026
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 25, 2026 07:04
@nikolauspschuetz

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Jul 25, 2026

Copy link
Copy Markdown

Submitted as pull.2186.git.1784998828879.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v1

To fetch this version to local tag pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v1

@nikolauspschuetz
nikolauspschuetz force-pushed the t6010-test-is-ancestor branch 2 times, most recently from e3a3981 to 0606bf5 Compare July 29, 2026 18:34
@gitgitgadget

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Nikolaus Schuetz via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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(+)

Thanks, will queue.

>
> 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

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

Phillip Wood wrote on the Git mailing list (how to reply to this email):

Hi Nikolaus

On 25/07/2026 18:00, Nikolaus Schuetz via GitGitGadget wrote:
> 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

> 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

> +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

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

User Phillip Wood <phillip.wood123@gmail.com> has been added to the cc: list.

@gitgitgadget

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

Phillip Wood <phillip.wood123@gmail.com> writes:

> Thanks for adding some tests for this option
>
>> 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? 

Good point.  It is often a lot more work to do so when writing these
new tests, and I suspect that is the reason why this new repository
was created, but I do not know whether, in the long run, it is
cheaper and more maintainable to reuse the test history that has been
used by all existing tests above.  The next developer who needs to
tweak the first test has 5 (the number of tests below) extra
constraints if we go that route, but a separate setup means the two
sets of tests are more isolated.

> 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.

@gitgitgadget

gitgitgadget Bot commented Jul 29, 2026

Copy link
Copy Markdown

This patch series was integrated into seen via git@5d1d3ed.

@gitgitgadget gitgitgadget Bot added the seen label Jul 29, 2026
@nikolauspschuetz
nikolauspschuetz force-pushed the t6010-test-is-ancestor branch 2 times, most recently from 36f711f to 94c8924 Compare July 30, 2026 05:34
`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>
@nikolauspschuetz
nikolauspschuetz force-pushed the t6010-test-is-ancestor branch from 94c8924 to 319bf89 Compare July 30, 2026 05:37
@nikolauspschuetz

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Jul 30, 2026

Copy link
Copy Markdown

Submitted as pull.2186.v2.git.1785392350660.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v2

To fetch this version to local tag pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2186/nikolauspschuetz/t6010-test-is-ancestor-v2

@gitgitgadget

gitgitgadget Bot commented Jul 30, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Nikolaus Schuetz via GitGitGadget" <gitgitgadget@gmail.com> writes:

>     Changes since v1, per review:
>     
>      * Reuse the E---D---C---B---A history and the G/H merges from the "set
>        up G and H" test instead of creating a separate repository.

Looks good.

>      * Add a test that --is-ancestor requires exactly two commits: too few
>        is a usage error (exit 129), while more than two is rejected with
>        "--is-ancestor takes exactly two commits" (exit 128).

OK.

Will queue.  Thanks.

@gitgitgadget

gitgitgadget Bot commented Jul 31, 2026

Copy link
Copy Markdown

This branch is now known as ns/merge-base-is-ancestor-tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants