From: Junio C Hamano Date: Mon, 17 Sep 2018 20:54:00 +0000 (-0700) Subject: Merge branch 'ab/fetch-tags-noclobber' X-Git-Tag: v2.20.0-rc0~229 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d39cab3989f9e660cae124f78143369b13ad2901;p=thirdparty%2Fgit.git Merge branch 'ab/fetch-tags-noclobber' The rules used by "git push" and "git fetch" to determine if a ref can or cannot be updated were inconsistent; specifically, fetching to update existing tags were allowed even though tags are supposed to be unmoving anchoring points. "git fetch" was taught to forbid updates to existing tags without the "--force" option. * ab/fetch-tags-noclobber: fetch: stop clobbering existing tags without --force fetch: document local ref updates with/without --force push doc: correct lies about how push refspecs work push doc: move mention of "tag " later in the prose push doc: remove confusing mention of remote merger fetch tests: add a test for clobbering tag behavior push tests: use spaces in interpolated string push tests: make use of unused $1 in test description fetch: change "branch" to "reference" in --force -h output --- d39cab3989f9e660cae124f78143369b13ad2901 diff --cc builtin/fetch.c index dc0931fb46,683f70d71e..0696abfc2a --- a/builtin/fetch.c +++ b/builtin/fetch.c @@@ -668,18 -664,22 +668,24 @@@ static int update_local_ref(struct 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); - updated = lookup_commit_reference_gently(&ref->new_oid, 1); + current = lookup_commit_reference_gently(the_repository, + &ref->old_oid, 1); + updated = lookup_commit_reference_gently(the_repository, + &ref->new_oid, 1); if (!current || !updated) { const char *msg; const char *what;