Merge branch 'ab/fetch-tags-noclobber'
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:54:00 +0000 (13:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:54:00 +0000 (13:54 -0700)
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 <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

1  2 
Documentation/fetch-options.txt
builtin/fetch.c
t/t5516-fetch-push.sh
t/t5612-clone-refspec.sh
Simple merge
diff --cc builtin/fetch.c
index dc0931fb464e5b81badf3a0a81f5dfd4b52129bf,683f70d71eda87196c4a4dd86cdce87bcc347e99..0696abfc2a158baa3177fa9e71e2c16bc64655a4
@@@ -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;
Simple merge
Simple merge