diff options
| -rw-r--r-- | Documentation/pull-fetch-param.txt | 15 | ||||
| -rw-r--r-- | builtin/fetch.c | 18 | ||||
| -rwxr-xr-x | t/t5516-fetch-push.sh | 5 | ||||
| -rwxr-xr-x | t/t5612-clone-refspec.sh | 4 |
4 files changed, 28 insertions, 14 deletions
diff --git a/Documentation/pull-fetch-param.txt b/Documentation/pull-fetch-param.txt index ab9617ad01..293c6b967d 100644 --- a/Documentation/pull-fetch-param.txt +++ b/Documentation/pull-fetch-param.txt @@ -43,10 +43,13 @@ same rules apply for fetching as when pushing, see the `<refspec>...` section of linkgit:git-push[1] for what those are. Exceptions to those rules particular to 'git fetch' are noted below. + -Unlike when pushing with linkgit:git-push[1], any updates to -`refs/tags/*` will be accepted without `+` in the refspec (or -`--force`). The receiving promiscuously considers all tag updates from -a remote to be forced fetches. +Until Git version 2.20, and unlike when pushing with +linkgit:git-push[1], any updates to `refs/tags/*` would be accepted +without `+` in the refspec (or `--force`). The receiving promiscuously +considered all tag updates from a remote to be forced fetches. Since +Git version 2.20, fetching to update `refs/tags/*` work the same way +as when pushing. I.e. any updates will be rejected without `+` in the +refspec (or `--force`). + Unlike when pushing with linkgit:git-push[1], any updates outside of `refs/{tags,heads}/*` will be accepted without `+` in the refspec (or @@ -54,6 +57,10 @@ Unlike when pushing with linkgit:git-push[1], any updates outside of a commit for another commit that's doesn't have the previous commit as an ancestor etc. + +Unlike when pushing with linkgit:git-push[1], there is no +configuration which'll amend these rules, and nothing like a +`pre-fetch` hook analogous to the `pre-receive` hook. ++ As with pushing with linkgit:git-push[1], all of the rules described above about what's not allowed as an update can be overridden by adding an the optional leading `+` to a refspec (or using `--force` diff --git a/builtin/fetch.c b/builtin/fetch.c index 767406ee05..683f70d71e 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -664,12 +664,18 @@ static int update_local_ref(struct ref *ref, if (!is_null_oid(&ref->old_oid) && starts_with(ref->name, "refs/tags/")) { - int r; - r = s_update_ref("updating tag", ref, 0); - format_display(display, r ? '!' : 't', _("[tag update]"), - r ? _("unable to update local ref") : NULL, - remote, pretty_ref, summary_width); - return r; + if (force || ref->force) { + int r; + r = s_update_ref("updating tag", ref, 0); + format_display(display, r ? '!' : 't', _("[tag update]"), + r ? _("unable to update local ref") : NULL, + remote, pretty_ref, summary_width); + return r; + } else { + format_display(display, '!', _("[rejected]"), _("would clobber existing tag"), + remote, pretty_ref, summary_width); + return 1; + } } current = lookup_commit_reference_gently(&ref->old_oid, 1); diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index a2d4f375fc..c545b16d13 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1015,7 +1015,7 @@ test_force_fetch_tag () { tag_type_description=$1 tag_args=$2 - test_expect_success "fetch will clobber an existing $tag_type_description" " + test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " mk_test testrepo heads/master && mk_child testrepo child1 && mk_child testrepo child2 && @@ -1027,7 +1027,8 @@ test_force_fetch_tag () { git add file1 && git commit -m 'file1' && git tag $tag_args testTag && - git -C ../child1 fetch origin tag testTag + test_must_fail git -C ../child1 fetch origin tag testTag && + git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' ) " } diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh index fac5a73851..6ea8f50dae 100755 --- a/t/t5612-clone-refspec.sh +++ b/t/t5612-clone-refspec.sh @@ -104,7 +104,7 @@ test_expect_success 'clone with --no-tags' ' test_expect_success '--single-branch while HEAD pointing at master' ' ( cd dir_master && - git fetch && + git fetch --force && git for-each-ref refs/remotes/origin | sed -e "/HEAD$/d" \ -e "s|/remotes/origin/|/heads/|" >../actual @@ -115,7 +115,7 @@ test_expect_success '--single-branch while HEAD pointing at master' ' test_cmp expect actual && ( cd dir_master && - git fetch --tags && + git fetch --tags --force && git for-each-ref refs/tags >../actual ) && git for-each-ref refs/tags >expect && |
