* [PATCH 0/2] fetch: clobber existing tags with --prune-tags
@ 2026-02-15 20:23 Orgad Shaneh via GitGitGadget
2026-02-15 20:23 ` [PATCH 1/2] fetch: add a test for --force flag Orgad Shaneh via GitGitGadget
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Orgad Shaneh via GitGitGadget @ 2026-02-15 20:23 UTC (permalink / raw)
To: git; +Cc: Orgad Shaneh
This was documented but not implemented.
In the flag description: prune local tags no longer on remote and clobber
changed tags
In the documentation: ... to prune local tags that don't exist on the
remote, and force-update those tags that differ.
Orgad Shaneh (2):
fetch: add a test for --force flag
fetch: clobber existing tags with --prune-tags
builtin/fetch.c | 2 +-
t/t5516-fetch-push.sh | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
base-commit: 852829b3dd2fe4e7c7fc4d8badde644cf1b66c74
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2200%2Forgads%2Ffetch-prune-clobber-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2200/orgads/fetch-prune-clobber-v1
Pull-Request: https://github.com/git/git/pull/2200
--
gitgitgadget
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 1/2] fetch: add a test for --force flag 2026-02-15 20:23 [PATCH 0/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget @ 2026-02-15 20:23 ` Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 2/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-11-21 21:46 ` [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 2 siblings, 0 replies; 12+ messages in thread From: Orgad Shaneh via GitGitGadget @ 2026-02-15 20:23 UTC (permalink / raw) To: git; +Cc: Orgad Shaneh, Orgad Shaneh From: Orgad Shaneh <orgad.shaneh@audiocodes.com> There are two ways to force-fetch tags that have changed: either by specifying an explicit forced ref (+refs/tags/*:refs/tags/*), or by using --force. The first approach was already tested, but the second was not. This has now been addressed. Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com> --- t/t5516-fetch-push.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 29e2f17608..31df7faf56 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1105,7 +1105,10 @@ test_force_fetch_tag () { git commit -m 'file1' && git tag $tag_args testTag && test_must_fail git -C ../child1 fetch origin tag testTag && - git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' + git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && + git tag $tag_args testTag HEAD^ && + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 fetch --force origin tag testTag ) " } -- gitgitgadget ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-02-15 20:23 [PATCH 0/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 1/2] fetch: add a test for --force flag Orgad Shaneh via GitGitGadget @ 2026-02-15 20:23 ` Orgad Shaneh via GitGitGadget 2026-03-18 8:27 ` Orgad Shaneh 2026-03-21 18:26 ` Junio C Hamano 2026-11-21 21:46 ` [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 2 siblings, 2 replies; 12+ messages in thread From: Orgad Shaneh via GitGitGadget @ 2026-02-15 20:23 UTC (permalink / raw) To: git; +Cc: Orgad Shaneh, Orgad Shaneh From: Orgad Shaneh <orgad.shaneh@audiocodes.com> This was documented but not implemented. In the flag description: prune local tags no longer on remote *and clobber changed tags* In the documentation: ... to prune local tags that don't exist on the remote, *and force-update those tags that differ*. Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com> --- builtin/fetch.c | 2 +- t/t5516-fetch-push.sh | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index a3bc7e9380..c212f50b86 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -981,7 +981,7 @@ static int update_local_ref(struct ref *ref, starts_with(ref->name, "refs/tags/")) { struct ref_update_display_info *info; - if (force || ref->force) { + if (force || ref->force || prune_tags) { int r; r = s_update_ref("updating tag", ref, transaction, 0); diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 31df7faf56..4d29043baf 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1092,7 +1092,7 @@ test_force_fetch_tag () { tag_type_description=$1 tag_args=$2 - test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " + test_expect_success "fetch will not clobber an existing $tag_type_description without --force or --prune-tags" " mk_test testrepo heads/main && mk_child testrepo child1 && mk_child testrepo child2 && @@ -1108,7 +1108,13 @@ test_force_fetch_tag () { git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && git tag $tag_args testTag HEAD^ && test_must_fail git -C ../child1 fetch origin tag testTag && - git -C ../child1 fetch --force origin tag testTag + git -C ../child1 fetch --force origin tag testTag && + git tag $tag_args testTag HEAD && + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 fetch --prune-tags origin tag testTag && + git tag $tag_args testTag HEAD^ && + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 -c fetch.prunetags=true fetch origin tag testTag ) " } -- gitgitgadget ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-02-15 20:23 ` [PATCH 2/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget @ 2026-03-18 8:27 ` Orgad Shaneh 2026-03-21 18:26 ` Junio C Hamano 1 sibling, 0 replies; 12+ messages in thread From: Orgad Shaneh @ 2026-03-18 8:27 UTC (permalink / raw) To: Orgad Shaneh via GitGitGadget; +Cc: git, Orgad Shaneh On Sun, Feb 15, 2026 at 10:23 PM Orgad Shaneh via GitGitGadget <gitgitgadget@gmail.com> wrote: > > From: Orgad Shaneh <orgad.shaneh@audiocodes.com> > > This was documented but not implemented. > > In the flag description: > prune local tags no longer on remote *and clobber changed tags* > > In the documentation: > ... to prune local tags that don't exist on the remote, *and > force-update those tags that differ*. > > Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com> > --- > builtin/fetch.c | 2 +- > t/t5516-fetch-push.sh | 10 ++++++++-- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/builtin/fetch.c b/builtin/fetch.c > index a3bc7e9380..c212f50b86 100644 > --- a/builtin/fetch.c > +++ b/builtin/fetch.c > @@ -981,7 +981,7 @@ static int update_local_ref(struct ref *ref, > starts_with(ref->name, "refs/tags/")) { > struct ref_update_display_info *info; > > - if (force || ref->force) { > + if (force || ref->force || prune_tags) { > int r; > > r = s_update_ref("updating tag", ref, transaction, 0); > diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh > index 31df7faf56..4d29043baf 100755 > --- a/t/t5516-fetch-push.sh > +++ b/t/t5516-fetch-push.sh > @@ -1092,7 +1092,7 @@ test_force_fetch_tag () { > tag_type_description=$1 > tag_args=$2 > > - test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " > + test_expect_success "fetch will not clobber an existing $tag_type_description without --force or --prune-tags" " > mk_test testrepo heads/main && > mk_child testrepo child1 && > mk_child testrepo child2 && > @@ -1108,7 +1108,13 @@ test_force_fetch_tag () { > git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && > git tag $tag_args testTag HEAD^ && > test_must_fail git -C ../child1 fetch origin tag testTag && > - git -C ../child1 fetch --force origin tag testTag > + git -C ../child1 fetch --force origin tag testTag && > + git tag $tag_args testTag HEAD && > + test_must_fail git -C ../child1 fetch origin tag testTag && > + git -C ../child1 fetch --prune-tags origin tag testTag && > + git tag $tag_args testTag HEAD^ && > + test_must_fail git -C ../child1 fetch origin tag testTag && > + git -C ../child1 -c fetch.prunetags=true fetch origin tag testTag > ) > " > } > -- > gitgitgadget Gently pinging this thread. I submitted this patch about a month ago and would appreciate any feedback once someone finds a moment to review it. Thanks! ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-02-15 20:23 ` [PATCH 2/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-03-18 8:27 ` Orgad Shaneh @ 2026-03-21 18:26 ` Junio C Hamano 2026-03-26 7:57 ` Orgad Shaneh 1 sibling, 1 reply; 12+ messages in thread From: Junio C Hamano @ 2026-03-21 18:26 UTC (permalink / raw) To: Orgad Shaneh via GitGitGadget Cc: git, Ævar Arnfjörð Bjarmason, Orgad Shaneh, Orgad Shaneh "Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Orgad Shaneh <orgad.shaneh@audiocodes.com> > > This was documented but not implemented. And instead what did the command do / how did the command behave? It also is curious when it was "broken". It could be that it was broken from day one when 97716d21 (fetch: add a --prune-tags option and fetch.pruneTags config, 2018-02-09) was written, c1a7902f (Merge branch 'ab/fetch-prune', 2018-03-06) merged it, and Git 2.17 was shipped with it, but knowing Ævar (by the way where is he these days???), I somehow doubt it. And unless it was broken from day one, we must find out if the change in behaviour was deliberate, in which case it would be the doucmentation and not the implementation that needs fixing. > In the flag description: > prune local tags no longer on remote *and clobber changed tags* > > In the documentation: > ... to prune local tags that don't exist on the remote, *and > force-update those tags that differ*. > ... > diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh > index 31df7faf56..4d29043baf 100755 > --- a/t/t5516-fetch-push.sh > +++ b/t/t5516-fetch-push.sh > @@ -1092,7 +1092,7 @@ test_force_fetch_tag () { > tag_type_description=$1 > tag_args=$2 > > - test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " > + test_expect_success "fetch will not clobber an existing $tag_type_description without --force or --prune-tags" " > mk_test testrepo heads/main && > mk_child testrepo child1 && > mk_child testrepo child2 && > @@ -1108,7 +1108,13 @@ test_force_fetch_tag () { > git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && > git tag $tag_args testTag HEAD^ && > test_must_fail git -C ../child1 fetch origin tag testTag && > - git -C ../child1 fetch --force origin tag testTag > + git -C ../child1 fetch --force origin tag testTag && > + git tag $tag_args testTag HEAD && > + test_must_fail git -C ../child1 fetch origin tag testTag && > + git -C ../child1 fetch --prune-tags origin tag testTag && > + git tag $tag_args testTag HEAD^ && > + test_must_fail git -C ../child1 fetch origin tag testTag && > + git -C ../child1 -c fetch.prunetags=true fetch origin tag testTag > ) > " > } None of the steps we see in the added test do not seem to check that --prune-tags does clobber existing tag that no longer exists on the other side. It only checks the "git fetch" command exits with status 0, but does not see if the tag actually went away after the operation is done. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-03-21 18:26 ` Junio C Hamano @ 2026-03-26 7:57 ` Orgad Shaneh 2026-09-13 19:03 ` Orgad Shaneh 0 siblings, 1 reply; 12+ messages in thread From: Orgad Shaneh @ 2026-03-26 7:57 UTC (permalink / raw) To: Junio C Hamano Cc: Orgad Shaneh via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Orgad Shaneh On Sat, Mar 21, 2026 at 8:27 PM Junio C Hamano <gitster@pobox.com> wrote: > > "Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > From: Orgad Shaneh <orgad.shaneh@audiocodes.com> > > > > This was documented but not implemented. > > And instead what did the command do / how did the command behave? Even when passing --prune-tags or setting fetch.pruneTags, git fetch fails to force-update tags, resulting in the following error: ! [rejected] testTag -> testTag (would clobber existing tag) Furthermore, when a tag clobber is rejected, the entire fetch operation fails, preventing the update of other refs and even new tags. > It also is curious when it was "broken". It could be that it was > broken from day one when 97716d21 (fetch: add a --prune-tags option > and fetch.pruneTags config, 2018-02-09) was written, c1a7902f (Merge > branch 'ab/fetch-prune', 2018-03-06) merged it, and Git 2.17 was > shipped with it, but knowing Ævar (by the way where is he these > days???), I somehow doubt it. > > And unless it was broken from day one, we must find out if the > change in behaviour was deliberate, in which case it would be the > doucmentation and not the implementation that needs fixing. I dug into the feature history and found: 1. The flag was added in 97716d21 (fetch: add a --prune-tags option and fetch.pruneTags config, 2018-02-09) as you mentioned. 2. Tag clobbering protection was added later in 0bc8d71b (fetch: stop clobbering existing tags without --force, 2018-08-31). It appears the --prune-tags flag was overlooked in that later commit, either in its behavior or its documentation. Since there is currently no way to suppress this error globally, if you consider the current behavior acceptable and prefer to fix the documentation, I suggest adding a fetch.force config to allow clobbering. > > git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && > > git tag $tag_args testTag HEAD^ && > > test_must_fail git -C ../child1 fetch origin tag testTag && > > - git -C ../child1 fetch --force origin tag testTag > > + git -C ../child1 fetch --force origin tag testTag && > > + git tag $tag_args testTag HEAD && > > + test_must_fail git -C ../child1 fetch origin tag testTag && > > + git -C ../child1 fetch --prune-tags origin tag testTag && > > + git tag $tag_args testTag HEAD^ && > > + test_must_fail git -C ../child1 fetch origin tag testTag && > > + git -C ../child1 -c fetch.prunetags=true fetch origin tag testTag > > ) > > " > > } > > None of the steps we see in the added test do not seem to check that > --prune-tags does clobber existing tag that no longer exists on the > other side. It only checks the "git fetch" command exits with > status 0, but does not see if the tag actually went away after the > operation is done. In these tests, the tag is being replaced rather than deleted. Existing tests for the pruning mechanism itself are located in t/t5510-fetch.sh. Would you like me to add a check for the tag content itself to verify the update? I suppose I should do the same for the existing test cases in that block as well. - Orgad ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-03-26 7:57 ` Orgad Shaneh @ 2026-09-13 19:03 ` Orgad Shaneh 2026-09-13 22:57 ` Junio C Hamano 0 siblings, 1 reply; 12+ messages in thread From: Orgad Shaneh @ 2026-09-13 19:03 UTC (permalink / raw) To: Junio C Hamano Cc: Orgad Shaneh via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Orgad Shaneh On Thu, Mar 26, 2026 at 9:57 AM Orgad Shaneh <orgads@gmail.com> wrote: > > On Sat, Mar 21, 2026 at 8:27 PM Junio C Hamano <gitster@pobox.com> wrote: > > > > None of the steps we see in the added test do not seem to check that > > --prune-tags does clobber existing tag that no longer exists on the > > other side. It only checks the "git fetch" command exits with > > status 0, but does not see if the tag actually went away after the > > operation is done. > > In these tests, the tag is being replaced rather than deleted. Existing > tests for the pruning mechanism itself are located in t/t5510-fetch.sh. > > Would you like me to add a check for the tag content itself to verify > the update? I suppose I should do the same for the existing test cases > in that block as well. Junio? - Orgad ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-09-13 19:03 ` Orgad Shaneh @ 2026-09-13 22:57 ` Junio C Hamano 2026-10-06 17:44 ` Orgad Shaneh 0 siblings, 1 reply; 12+ messages in thread From: Junio C Hamano @ 2026-09-13 22:57 UTC (permalink / raw) To: Orgad Shaneh Cc: Orgad Shaneh via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Orgad Shaneh Orgad Shaneh <orgads@gmail.com> writes: > On Thu, Mar 26, 2026 at 9:57 AM Orgad Shaneh <orgads@gmail.com> wrote: >> >> On Sat, Mar 21, 2026 at 8:27 PM Junio C Hamano <gitster@pobox.com> wrote: >> > >> > None of the steps we see in the added test do not seem to check that >> > --prune-tags does clobber existing tag that no longer exists on the >> > other side. It only checks the "git fetch" command exits with >> > status 0, but does not see if the tag actually went away after the >> > operation is done. >> >> In these tests, the tag is being replaced rather than deleted. Existing >> tests for the pruning mechanism itself are located in t/t5510-fetch.sh. >> >> Would you like me to add a check for the tag content itself to verify >> the update? I suppose I should do the same for the existing test cases >> in that block as well. > > Junio? Sorry, but I do not have 6 month old discussions in my context window, so no immediate comment. I'll respond only after I swap the context back in but not today (yet). Thanks. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags 2026-09-13 22:57 ` Junio C Hamano @ 2026-10-06 17:44 ` Orgad Shaneh 0 siblings, 0 replies; 12+ messages in thread From: Orgad Shaneh @ 2026-10-06 17:44 UTC (permalink / raw) To: Junio C Hamano Cc: Orgad Shaneh via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Orgad Shaneh On Mon, Sep 14, 2026 at 1:57 AM Junio C Hamano <gitster@pobox.com> wrote: > > Orgad Shaneh <orgads@gmail.com> writes: > > > On Thu, Mar 26, 2026 at 9:57 AM Orgad Shaneh <orgads@gmail.com> wrote: > >> > >> On Sat, Mar 21, 2026 at 8:27 PM Junio C Hamano <gitster@pobox.com> wrote: > >> > > >> > None of the steps we see in the added test do not seem to check that > >> > --prune-tags does clobber existing tag that no longer exists on the > >> > other side. It only checks the "git fetch" command exits with > >> > status 0, but does not see if the tag actually went away after the > >> > operation is done. > >> > >> In these tests, the tag is being replaced rather than deleted. Existing > >> tests for the pruning mechanism itself are located in t/t5510-fetch.sh. > >> > >> Would you like me to add a check for the tag content itself to verify > >> the update? I suppose I should do the same for the existing test cases > >> in that block as well. > > > > Junio? > > Sorry, but I do not have 6 month old discussions in my context > window, so no immediate comment. I'll respond only after I swap the > context back in but not today (yet). Maybe today? ;) - Orgad ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags 2026-02-15 20:23 [PATCH 0/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 1/2] fetch: add a test for --force flag Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 2/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget @ 2026-11-21 21:46 ` Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 1/2] fetch: test that --force clobbers a changed tag Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 2/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 2 siblings, 2 replies; 12+ messages in thread From: Orgad Shaneh @ 2026-11-21 21:46 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Karthik Nayak, Ævar Arnfjörð Bjarmason --prune-tags is documented to force-update tags that changed on the remote, but since 0bc8d71b99 (Git 2.20) it rejects them with "would clobber existing tag". Changes since v1: * Instead of treating --prune-tags like --force for tags, add "+" to the refspec that --prune-tags implies. v1 also forced tags fetched with an explicit refspec when fetch.pruneTags was set, even though tags are not pruned in that case. * The commit message now says what fetch does today, and where this broke. * The tests check that the local tag was actually updated, not only that fetch succeeded, and that "git fetch origin tag <name>" is still refused with fetch.pruneTags set. * Rebased on current master. Orgad Shaneh (2): fetch: test that --force clobbers a changed tag fetch: make --prune-tags clobber changed tags Documentation/config/fetch.adoc | 2 +- Documentation/git-fetch.adoc | 2 +- builtin/fetch.c | 4 ++-- t/t5516-fetch-push.sh | 35 ++++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) Range-diff against v1: 1: 3a5b1c73a6 ! 1: 6ee374acd4 fetch: add a test for --force flag @@ Metadata Author: Orgad Shaneh <orgads@gmail.com> ## Commit message ## - fetch: add a test for --force flag + fetch: test that --force clobbers a changed tag - There are two ways to force-fetch tags that have changed: either by - specifying an explicit forced ref (+refs/tags/*:refs/tags/*), or by - using --force. + Changed tags can be force-fetched with a "+" refspec or with --force, + but only the refspec was tested. The test also didn't check that the + tag was actually updated, only that fetch succeeded. - The first approach was already tested, but the second was not. This - has now been addressed. + Add the --force case, and check the tag after each forced fetch. - Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com> + Signed-off-by: Orgad Shaneh <orgads@gmail.com> ## t/t5516-fetch-push.sh ## +@@ t/t5516-fetch-push.sh: test_force_push_tag () { + test_force_push_tag "lightweight tag" "-f" + test_force_push_tag "annotated tag" "-f -a -m'tag message'" + ++check_child1_tag () { ++ git rev-parse testTag >expect && ++ git -C ../child1 rev-parse testTag >actual && ++ test_cmp expect actual ++} ++ + test_force_fetch_tag () { + tag_type_description=$1 + tag_args=$2 @@ t/t5516-fetch-push.sh: test_force_fetch_tag () { git commit -m 'file1' && git tag $tag_args testTag && test_must_fail git -C ../child1 fetch origin tag testTag && - git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' + git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && ++ check_child1_tag && + git tag $tag_args testTag HEAD^ && + test_must_fail git -C ../child1 fetch origin tag testTag && -+ git -C ../child1 fetch --force origin tag testTag ++ git -C ../child1 fetch --force origin tag testTag && ++ check_child1_tag ) " } 2: ae82d31bfb < -: ---------- fetch: clobber existing tags with --prune-tags -: ---------- > 2: 3ed44788d7 fetch: make --prune-tags clobber changed tags base-commit: f7de81456940dd6f3274e461149bba12965de609 -- 2.53.0 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/2] fetch: test that --force clobbers a changed tag 2026-11-21 21:46 ` [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh @ 2026-11-21 21:46 ` Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 2/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 1 sibling, 0 replies; 12+ messages in thread From: Orgad Shaneh @ 2026-11-21 21:46 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Karthik Nayak, Ævar Arnfjörð Bjarmason Changed tags can be force-fetched with a "+" refspec or with --force, but only the refspec was tested. The test also didn't check that the tag was actually updated, only that fetch succeeded. Add the --force case, and check the tag after each forced fetch. Signed-off-by: Orgad Shaneh <orgads@gmail.com> --- t/t5516-fetch-push.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 2f46ddc9ba..68e0e2de27 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1160,6 +1160,12 @@ test_force_push_tag () { test_force_push_tag "lightweight tag" "-f" test_force_push_tag "annotated tag" "-f -a -m'tag message'" +check_child1_tag () { + git rev-parse testTag >expect && + git -C ../child1 rev-parse testTag >actual && + test_cmp expect actual +} + test_force_fetch_tag () { tag_type_description=$1 tag_args=$2 @@ -1177,7 +1183,12 @@ test_force_fetch_tag () { git commit -m 'file1' && git tag $tag_args testTag && test_must_fail git -C ../child1 fetch origin tag testTag && - git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' + git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' && + check_child1_tag && + git tag $tag_args testTag HEAD^ && + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 fetch --force origin tag testTag && + check_child1_tag ) " } -- 2.53.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/2] fetch: make --prune-tags clobber changed tags 2026-11-21 21:46 ` [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 1/2] fetch: test that --force clobbers a changed tag Orgad Shaneh @ 2026-11-21 21:46 ` Orgad Shaneh 1 sibling, 0 replies; 12+ messages in thread From: Orgad Shaneh @ 2026-11-21 21:46 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Karthik Nayak, Ævar Arnfjörð Bjarmason The docs say --prune-tags will "force-update those tags that differ", and the option help says "clobber changed tags", but it doesn't do that. When a tag changes on the remote, fetch fails with: ! [rejected] t1 -> t1 (would clobber existing tag) When --prune-tags was added in 97716d217c (fetch: add a --prune-tags option and fetch.pruneTags config, 2018-02-09), fetch always updated changed tags, so the docs were right. Later, 0bc8d71b99 (fetch: stop clobbering existing tags without --force, 2018-08-31) required "+" or --force for that, and --prune-tags was missed: its refspec "refs/tags/*:refs/tags/*" has no "+". That commit doesn't mention --prune-tags at all, so I don't think it was intentional. Fix it by adding "+" to the refspec, and update the docs that quote it. Fetching a tag by name is not affected. --prune-tags is ignored when refspecs are given on the command line, so "git fetch origin tag foo" still needs --force, even with fetch.pruneTags set. Signed-off-by: Orgad Shaneh <orgads@gmail.com> --- Documentation/config/fetch.adoc | 2 +- Documentation/git-fetch.adoc | 2 +- builtin/fetch.c | 4 ++-- t/t5516-fetch-push.sh | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Documentation/config/fetch.adoc b/Documentation/config/fetch.adoc index 00435e9a16..0dc4a11706 100644 --- a/Documentation/config/fetch.adoc +++ b/Documentation/config/fetch.adoc @@ -44,7 +44,7 @@ `fetch.pruneTags`:: If true, fetch will automatically behave as if the - `refs/tags/*:refs/tags/*` refspec was provided when pruning, + `+refs/tags/*:refs/tags/*` refspec was provided when pruning, if not set already. This allows for setting both this option and `fetch.prune` to maintain a 1=1 mapping to upstream refs. See also `remote.<name>.pruneTags` and the PRUNING diff --git a/Documentation/git-fetch.adoc b/Documentation/git-fetch.adoc index 61fed797af..4c18e2b144 100644 --- a/Documentation/git-fetch.adoc +++ b/Documentation/git-fetch.adoc @@ -161,7 +161,7 @@ with `fetch.pruneTags` or `remote.<name>.pruneTags` in the config. See linkgit:git-config[1]. The `--prune-tags` option is equivalent to having -`refs/tags/*:refs/tags/*` declared in the refspecs of the remote. This +`+refs/tags/*:refs/tags/*` declared in the refspecs of the remote. This can lead to some seemingly strange interactions: ------------------------------------------------ diff --git a/builtin/fetch.c b/builtin/fetch.c index c646bc6698..291c5ce91b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -2520,10 +2520,10 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, maybe_prune_tags = prune_tags_ok && prune_tags; if (maybe_prune_tags && remote_via_config) - refspec_append(&remote->fetch, TAG_REFSPEC); + refspec_append(&remote->fetch, "+" TAG_REFSPEC); if (maybe_prune_tags && (argc || !remote_via_config)) - refspec_append(&rs, TAG_REFSPEC); + refspec_append(&rs, "+" TAG_REFSPEC); for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "tag")) { diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 68e0e2de27..c20fd1eebf 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1191,6 +1191,28 @@ test_force_fetch_tag () { check_child1_tag ) " + + test_expect_success "fetch --prune-tags clobbers an existing $tag_type_description" " + mk_test testrepo heads/main && + mk_child testrepo child1 && + ( + cd testrepo && + git tag testTag && + git -C ../child1 fetch origin tag testTag && + >file1 && + git add file1 && + git commit -m 'file1' && + git tag $tag_args testTag && + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 fetch --prune --prune-tags origin && + check_child1_tag && + git tag $tag_args testTag HEAD^ && + test_must_fail git -C ../child1 -c fetch.pruneTags=true \ + fetch --prune origin tag testTag && + git -C ../child1 -c fetch.pruneTags=true fetch --prune origin && + check_child1_tag + ) + " } test_force_fetch_tag "lightweight tag" "-f" -- 2.53.0 ^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-21 21:46 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-15 20:23 [PATCH 0/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 1/2] fetch: add a test for --force flag Orgad Shaneh via GitGitGadget 2026-02-15 20:23 ` [PATCH 2/2] fetch: clobber existing tags with --prune-tags Orgad Shaneh via GitGitGadget 2026-03-18 8:27 ` Orgad Shaneh 2026-03-21 18:26 ` Junio C Hamano 2026-03-26 7:57 ` Orgad Shaneh 2026-09-13 19:03 ` Orgad Shaneh 2026-09-13 22:57 ` Junio C Hamano 2026-10-06 17:44 ` Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 0/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 1/2] fetch: test that --force clobbers a changed tag Orgad Shaneh 2026-11-21 21:46 ` [PATCH v2 2/2] fetch: make --prune-tags clobber changed tags Orgad Shaneh
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox