Thread View: linux.kernel.git
3 messages
3 total messages
Started by Orgad Shaneh
Sat, 21 Nov 2026 21:46
[PATCH v2 0/2] fetch: make --prune-tags clobber changed tags
Author: Orgad Shaneh
Date: Sat, 21 Nov 2026 21:46
Date: Sat, 21 Nov 2026 21:46
89 lines
14178 bytes
14178 bytes
--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
[PATCH v2 1/2] fetch: test that --force clobbers a changed tag
Author: Orgad Shaneh
Date: Sat, 21 Nov 2026 21:46
Date: Sat, 21 Nov 2026 21:46
45 lines
12193 bytes
12193 bytes
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
[PATCH v2 2/2] fetch: make --prune-tags clobber changed tags
Author: Orgad Shaneh
Date: Sat, 21 Nov 2026 21:46
Date: Sat, 21 Nov 2026 21:46
107 lines
14972 bytes
14972 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads