Re: [PATCH v3] checkout: add --fetch to fetch remote before resolving start-point
- From
Ramsay Jones <ramsay@ramsayjones.plus.com>
- Date
- Apr 26, 2026, 15:54 UTC
- Message-ID
- <0c589c18-e8f6-42ac-842f-ec1f5f6fb3ff@ramsayjones.plus.com>
- In-Reply-To
- <pull.2281.v3.git.git.1777188295021.gitgitgadget@gmail.com>
On 26/04/2026 8:24 am, Harald Nordgren via GitGitGadget wrote:
> From: Harald Nordgren <haraldnordgren@gmail.com> >
[snip]
Show 77 quoted lines
> diff --git a/t/t7201-co.sh b/t/t7201-co.sh > index 9bcf7c0b40..cf2ceb4052 100755 > --- a/t/t7201-co.sh > +++ b/t/t7201-co.sh > @@ -801,4 +801,72 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' ' > test_cmp_config "" --default "" branch.main2.merge > ' > > +test_expect_success 'setup upstream for --fetch tests' ' > + git checkout main && > + git init fetch_upstream && > + test_commit -C fetch_upstream u_main && > + git remote add fetch_upstream fetch_upstream && > + git fetch fetch_upstream && > + git -C fetch_upstream checkout -b fetch_new && > + test_commit -C fetch_upstream u_new > +' > + > +test_expect_success 'checkout --fetch -b picks up branch created upstream after clone' ' > + git checkout main && > + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_new && > + git checkout --fetch -b local_new fetch_upstream/fetch_new && > + test_cmp_rev refs/remotes/fetch_upstream/fetch_new HEAD > +' > + > +test_expect_success 'checkout --fetch <remote>/<branch> leaves other tracking branches untouched' ' > + git checkout main && > + git -C fetch_upstream checkout -b fetch_target && > + test_commit -C fetch_upstream u_target_pre && > + git -C fetch_upstream checkout -b fetch_other && > + test_commit -C fetch_upstream u_other_pre && > + git fetch fetch_upstream && > + other_before=$(git rev-parse refs/remotes/fetch_upstream/fetch_other) && > + git -C fetch_upstream checkout fetch_target && > + test_commit -C fetch_upstream u_target_post && > + git -C fetch_upstream checkout fetch_other && > + test_commit -C fetch_upstream u_other_post && > + git checkout --fetch -b local_target fetch_upstream/fetch_target && > + test_cmp_rev refs/remotes/fetch_upstream/fetch_target HEAD && > + test "$(git rev-parse refs/remotes/fetch_upstream/fetch_other)" = "$other_before" > +' > + > +test_expect_success 'checkout --fetch with bare remote name fetches the remote' ' > + git checkout main && > + git -C fetch_upstream checkout -b fetch_new2 && > + test_commit -C fetch_upstream u_new2 && > + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_new2 && > + git checkout --fetch -b local_from_remote fetch_upstream && > + git rev-parse --verify refs/remotes/fetch_upstream/fetch_new2 > +' > + > +test_expect_success 'checkout --fetch aborts and does not create branch on fetch failure' ' > + git checkout main && > + test_might_fail git branch -D bogus && > + test_must_fail git checkout --fetch -b bogus fetch_upstream/does_not_exist && > + test_must_fail git rev-parse --verify refs/heads/bogus > +' > + > +test_expect_success 'checkout.fetch=true enables fetching without --fetch' ' > + git checkout main && > + git -C fetch_upstream checkout -b fetch_cfg && > + test_commit -C fetch_upstream u_cfg && > + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_cfg && > + git -c checkout.fetch=true checkout -b local_cfg fetch_upstream/fetch_cfg && > + test_cmp_rev refs/remotes/fetch_upstream/fetch_cfg HEAD > +' > + > +test_expect_success 'switch --fetch -c picks up branch created upstream after clone' ' > + git checkout main && > + git -C fetch_upstream checkout -b fetch_switch && > + test_commit -C fetch_upstream u_switch && > + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_switch && > + git switch --fetch -c local_switch fetch_upstream/fetch_switch && > + test_cmp_rev refs/remotes/fetch_upstream/fetch_switch HEAD > +' > + > test_done
Still just skimming the list, so ... ;)
I seem to have missed v2 (but I guess the config name changed in v2), but it seems that there is still no test that confirms '--no-fetch' can countermand the config variable (or, indeed, an earlier command-line '--fetch' etc,.).
[I would have no use for this facility (I have _never_ used git-pull for similar reasons) since I would find it odd to 'mash' git-fetch into git-checkout/switch! :) ]
ATB, Ramsay Jones