From: Orgad Shaneh <orgads@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Karthik Nayak" <karthik.188@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 2/2] fetch: make --prune-tags clobber changed tags
Date: Sat, 21 Nov 2026 21:46:33 +0000 [thread overview]
Message-ID: <20261121214633.1523706-3-orgads@gmail.com> (raw)
In-Reply-To: <20261121214633.1523706-1-orgads@gmail.com>
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
prev parent reply other threads:[~2026-11-21 21:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Orgad Shaneh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121214633.1523706-3-orgads@gmail.com \
--to=orgads@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.