diff mbox series

[v3,2/2] t3200: tests for new branch.autosetupmerge option "simple"

Message ID d5b18c7949fdea966d31b2b8ca3f8aa8ed3a86b6.1646032466.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series adding new branch.autosetupmerge option "simple" | expand

Commit Message

Tao Klerks Feb. 28, 2022, 7:14 a.m. UTC
From: Tao Klerks <tao@klerks.biz>

In the previous commit a new autosetupmerge option was introduced.

Extend the existing branch tests with three new cases testing this
option - the obvious matching-name and non-matching-name cases, and
also a non-matching-ref-type case.

The matching-name case needs to temporarily create an independent
repo to fetch from, as the general strategy of using the local repo as
the remote in these tests precludes locally branching with the same
name as in the "remote".

Signed-off-by: Tao Klerks <tao@klerks.biz>
---
 t/t3200-branch.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Ævar Arnfjörð Bjarmason Feb. 28, 2022, 9:34 a.m. UTC | #1
On Mon, Feb 28 2022, Tao Klerks via GitGitGadget wrote:

> From: Tao Klerks <tao@klerks.biz>
>
> In the previous commit a new autosetupmerge option was introduced.
>
> Extend the existing branch tests with three new cases testing this
> option - the obvious matching-name and non-matching-name cases, and
> also a non-matching-ref-type case.
>
> The matching-name case needs to temporarily create an independent
> repo to fetch from, as the general strategy of using the local repo as
> the remote in these tests precludes locally branching with the same
> name as in the "remote".
>
> Signed-off-by: Tao Klerks <tao@klerks.biz>
> ---
>  t/t3200-branch.sh | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index 7a0ff75ba86..15cc58f1e64 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -886,6 +886,41 @@ test_expect_success 'branch from tag w/--track causes failure' '
>  	test_must_fail git branch --track my11 foobar
>  '
>  
> +test_expect_success 'simple tracking works when remote branch name matches' '
> +	test_create_repo otherserver &&
> +	test_commit -C otherserver my_commit 1 &&
> +	git -C otherserver branch feature &&
> +	git config branch.autosetupmerge simple &&
> +	git config remote.otherserver.url otherserver &&
> +	git config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* &&

Shouldn't these use test_config, or if the tests below need them do that
via a helper, so later added tests don't need to reset this state?

> +	git fetch otherserver &&
> +	git branch feature otherserver/feature &&
> +	rm -fr otherserver &&

Instead of "rm -rf" after, do above:

    test_when_finished "rm -rf otherserver" &&
    git init otherserver

(you don't need "test_create_repo" either, just use "git init")

> +	test $(git config branch.feature.remote) = otherserver &&
> +	test $(git config branch.feature.merge) = refs/heads/feature

Use:

    echo otherserver >expect &&
    git config ... >actual &&
    test_cmp expect actual

etc., the pattern you're using here will hide git's exit code on
segfaults, abort() etc., and also makes for less useful debug info on
failure than test_cmp.

    
> +'
> +
> +test_expect_success 'simple tracking skips when remote branch name does not match' '
> +	git config branch.autosetupmerge simple &&
> +	git config remote.local.url . &&
> +	git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&

ditto config setup above, this is quite hard to follow in sequence since
yo uneed to reason about all existing config. Let's start with a clean
slate for each test_expect_success and setup the specific config we want
instead.fallow since

> +	(git show-ref -q refs/remotes/local/main || git fetch local) &&

This likewise hides segfaults etc. Use:

    test_might_fail git show-ref ...

But maybe this whole thing should use "git rev-parse --verify" or
something?

> +	git branch my-other local/main &&
> +	test -z "$(git config branch.my-other.remote)" &&
> +	test -z "$(git config branch.my-other.merge)"

ditto test_cmp comments, but here:

    git ... >out &&
    test_must_be_empty out

> +'
> +
> +test_expect_success 'simple tracking skips when remote ref is not a branch' '
> +	git config branch.autosetupmerge simple &&
> +	git tag mytag12 main &&
> +	git config remote.localtags.url . &&
> +	git config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* &&
> +	(git show-ref -q refs/remotes/localtags/mytag12 || git fetch localtags) &&
> +	git branch mytag12 localtags/mytag12 &&
> +	test -z "$(git config branch.mytag12.remote)" &&
> +	test -z "$(git config branch.mytag12.merge)"

ditto above.

> +'
> +
>  test_expect_success '--set-upstream-to fails on multiple branches' '
>  	echo "fatal: too many arguments to set new upstream" >expect &&
>  	test_must_fail git branch --set-upstream-to main a b c 2>err &&
Eric Sunshine March 1, 2022, 2:58 a.m. UTC | #2
On Mon, Feb 28, 2022 at 5:54 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Mon, Feb 28 2022, Tao Klerks via GitGitGadget wrote:
> > +     test $(git config branch.feature.remote) = otherserver &&
> > +     test $(git config branch.feature.merge) = refs/heads/feature
>
> Use:
>
>     echo otherserver >expect &&
>     git config ... >actual &&
>     test_cmp expect actual
>
> etc., the pattern you're using here will hide git's exit code on
> segfaults, abort() etc., and also makes for less useful debug info on
> failure than test_cmp.

Better yet, use test_cmp_config():

    test_cmp_config otherserver branch.feature.remote &&
Tao Klerks March 1, 2022, 9:59 a.m. UTC | #3
On Mon, Feb 28, 2022 at 10:39 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
>
> On Mon, Feb 28 2022, Tao Klerks via GitGitGadget wrote:
>
> > +test_expect_success 'simple tracking works when remote branch name matches' '
> > +     test_create_repo otherserver &&
> > +     test_commit -C otherserver my_commit 1 &&
> > +     git -C otherserver branch feature &&
> > +     git config branch.autosetupmerge simple &&
> > +     git config remote.otherserver.url otherserver &&
> > +     git config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* &&
>
> Shouldn't these use test_config, or if the tests below need them do that
> via a helper, so later added tests don't need to reset this state?

Yes, I will look at this; I was naively (and clearly incorrectly)
following a pattern I saw in this same test file.

>
> > +     git fetch otherserver &&
> > +     git branch feature otherserver/feature &&
> > +     rm -fr otherserver &&
>
> Instead of "rm -rf" after, do above:
>
>     test_when_finished "rm -rf otherserver" &&
>     git init otherserver
>
> (you don't need "test_create_repo" either, just use "git init")

Will do, thx!

>
> > +     test $(git config branch.feature.remote) = otherserver &&
> > +     test $(git config branch.feature.merge) = refs/heads/feature
>
> Use:
>
>     echo otherserver >expect &&
>     git config ... >actual &&
>     test_cmp expect actual
>
> etc., the pattern you're using here will hide git's exit code on
> segfaults, abort() etc., and also makes for less useful debug info on
> failure than test_cmp.

Again, thank you! (I will look at test_cmp_config() as Eric suggested)

>
>
> > +'
> > +
> > +test_expect_success 'simple tracking skips when remote branch name does not match' '
> > +     git config branch.autosetupmerge simple &&
> > +     git config remote.local.url . &&
> > +     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
>
> ditto config setup above, this is quite hard to follow in sequence since
> yo uneed to reason about all existing config. Let's start with a clean
> slate for each test_expect_success and setup the specific config we want
> instead.fallow since
>
> > +     (git show-ref -q refs/remotes/local/main || git fetch local) &&
>
> This likewise hides segfaults etc. Use:
>
>     test_might_fail git show-ref ...
>
> But maybe this whole thing should use "git rev-parse --verify" or
> something?

Honestly, I think this bad pattern is just a premature optimization against
a pretty-fast local fetch. Will simplify, and do the same for existing
patterns in this file.

>
> > +     git branch my-other local/main &&
> > +     test -z "$(git config branch.my-other.remote)" &&
> > +     test -z "$(git config branch.my-other.merge)"
>
> ditto test_cmp comments, but here:
>
>     git ... >out &&
>     test_must_be_empty out
>

OK, will look, thx.
Tao Klerks March 1, 2022, 9:59 a.m. UTC | #4
On Tue, Mar 1, 2022 at 3:59 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> On Mon, Feb 28, 2022 at 5:54 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
> > On Mon, Feb 28 2022, Tao Klerks via GitGitGadget wrote:
> > > +     test $(git config branch.feature.remote) = otherserver &&
> > > +     test $(git config branch.feature.merge) = refs/heads/feature
> >
> > Use:
> >
> >     echo otherserver >expect &&
> >     git config ... >actual &&
> >     test_cmp expect actual
> >
> > etc., the pattern you're using here will hide git's exit code on
> > segfaults, abort() etc., and also makes for less useful debug info on
> > failure than test_cmp.
>
> Better yet, use test_cmp_config():
>
>     test_cmp_config otherserver branch.feature.remote &&

Noted, thx.
diff mbox series

Patch

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 7a0ff75ba86..15cc58f1e64 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -886,6 +886,41 @@  test_expect_success 'branch from tag w/--track causes failure' '
 	test_must_fail git branch --track my11 foobar
 '
 
+test_expect_success 'simple tracking works when remote branch name matches' '
+	test_create_repo otherserver &&
+	test_commit -C otherserver my_commit 1 &&
+	git -C otherserver branch feature &&
+	git config branch.autosetupmerge simple &&
+	git config remote.otherserver.url otherserver &&
+	git config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* &&
+	git fetch otherserver &&
+	git branch feature otherserver/feature &&
+	rm -fr otherserver &&
+	test $(git config branch.feature.remote) = otherserver &&
+	test $(git config branch.feature.merge) = refs/heads/feature
+'
+
+test_expect_success 'simple tracking skips when remote branch name does not match' '
+	git config branch.autosetupmerge simple &&
+	git config remote.local.url . &&
+	git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+	(git show-ref -q refs/remotes/local/main || git fetch local) &&
+	git branch my-other local/main &&
+	test -z "$(git config branch.my-other.remote)" &&
+	test -z "$(git config branch.my-other.merge)"
+'
+
+test_expect_success 'simple tracking skips when remote ref is not a branch' '
+	git config branch.autosetupmerge simple &&
+	git tag mytag12 main &&
+	git config remote.localtags.url . &&
+	git config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* &&
+	(git show-ref -q refs/remotes/localtags/mytag12 || git fetch localtags) &&
+	git branch mytag12 localtags/mytag12 &&
+	test -z "$(git config branch.mytag12.remote)" &&
+	test -z "$(git config branch.mytag12.merge)"
+'
+
 test_expect_success '--set-upstream-to fails on multiple branches' '
 	echo "fatal: too many arguments to set new upstream" >expect &&
 	test_must_fail git branch --set-upstream-to main a b c 2>err &&