Merge branch 'km/branch-get-push-while-detached' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:32:08 +0000 (13:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:32:08 +0000 (13:32 -0800)
"git <cmd> @{push}" on a detached HEAD used to segfault; it has
been corrected to error out with a message.

* km/branch-get-push-while-detached:
branch_get_push: do not segfault when HEAD is detached

1  2 
remote.c
diff --combined remote.c
index ad6c5424edab2ae15ac17bfcf12ac4ee93b5aa3f,d1a7a4032b636739c2a15eb415982a4714d19b70..d5eaec73742e74738c522cdc36ba9bf811b158b2
+++ b/remote.c
@@@ -1544,7 -1544,8 +1544,7 @@@ void set_ref_status_for_push(struct re
                 * branch.
                 */
                if (ref->expect_old_sha1) {
 -                      if (ref->expect_old_no_trackback ||
 -                          oidcmp(&ref->old_oid, &ref->old_oid_expect))
 +                      if (oidcmp(&ref->old_oid, &ref->old_oid_expect))
                                reject_reason = REF_STATUS_REJECT_STALE;
                        else
                                /* If the ref isn't stale then force the update. */
@@@ -1716,9 -1717,6 +1716,6 @@@ static const char *branch_get_push_1(st
  {
        struct remote *remote;
  
-       if (!branch)
-               return error_buf(err, _("HEAD does not point to a branch"));
        remote = remote_get(pushremote_for_branch(branch, NULL));
        if (!remote)
                return error_buf(err,
  
  const char *branch_get_push(struct branch *branch, struct strbuf *err)
  {
+       if (!branch)
+               return error_buf(err, _("HEAD does not point to a branch"));
        if (!branch->push_tracking_ref)
                branch->push_tracking_ref = branch_get_push_1(branch, err);
        return branch->push_tracking_ref;
@@@ -2073,7 -2074,7 +2073,7 @@@ int format_tracking_info(struct branch 
                        _("Your branch is based on '%s', but the upstream is gone.\n"),
                        base);
                if (advice_status_hints)
 -                      strbuf_addf(sb,
 +                      strbuf_addstr(sb,
                                _("  (use \"git branch --unset-upstream\" to fixup)\n"));
        } else if (!ours && !theirs) {
                strbuf_addf(sb,
                           ours),
                        base, ours);
                if (advice_status_hints)
 -                      strbuf_addf(sb,
 +                      strbuf_addstr(sb,
                                _("  (use \"git push\" to publish your local commits)\n"));
        } else if (!ours) {
                strbuf_addf(sb,
                           theirs),
                        base, theirs);
                if (advice_status_hints)
 -                      strbuf_addf(sb,
 +                      strbuf_addstr(sb,
                                _("  (use \"git pull\" to update your local branch)\n"));
        } else {
                strbuf_addf(sb,
                           ours + theirs),
                        base, ours, theirs);
                if (advice_status_hints)
 -                      strbuf_addf(sb,
 +                      strbuf_addstr(sb,
                                _("  (use \"git pull\" to merge the remote branch into yours)\n"));
        }
        free(base);
@@@ -2293,8 -2294,6 +2293,8 @@@ int parse_push_cas_option(struct push_c
        entry = add_cas_entry(cas, arg, colon - arg);
        if (!*colon)
                entry->use_tracking = 1;
 +      else if (!colon[1])
 +              hashclr(entry->expect);
        else if (get_sha1(colon + 1, entry->expect))
                return error("cannot parse expected object name '%s'", colon + 1);
        return 0;
@@@ -2344,7 -2343,7 +2344,7 @@@ static void apply_cas(struct push_cas_o
                if (!entry->use_tracking)
                        hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
                else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
 -                      ref->expect_old_no_trackback = 1;
 +                      oidclr(&ref->old_oid_expect);
                return;
        }
  
  
        ref->expect_old_sha1 = 1;
        if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
 -              ref->expect_old_no_trackback = 1;
 +              oidclr(&ref->old_oid_expect);
  }
  
  void apply_push_cas(struct push_cas_option *cas,