Re: [PATCH 2/2] fetch: clobber existing tags with --prune-tags
- From
Orgad Shaneh <orgads@gmail.com>
- Date
- Mar 26, 2026, 07:57 UTC
- Message-ID
- <CAGHpTBJKaTURMJmJ6W4iiCAy3-M2YWb48rF8GMoEPCfpGcE=QA@mail.gmail.com>
- In-Reply-To
- <xmqq1phdavik.fsf@gitster.g>
On Sat, Mar 21, 2026 at 8:27 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> > "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.
Show 10 quoted lines
> 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.
Show 20 quoted lines
> > 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