From: Junio C Hamano Date: Wed, 18 Jan 2017 23:12:14 +0000 (-0800) Subject: Merge branch 'km/branch-get-push-while-detached' X-Git-Tag: v2.12.0-rc0~69 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b85f79c7dd35b495ce94bf58b61832c6030751cf?hp=-c Merge branch 'km/branch-get-push-while-detached' "git @{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 --- b85f79c7dd35b495ce94bf58b61832c6030751cf diff --combined remote.c index ad6c5424ed,d1a7a4032b..d5eaec7374 --- a/remote.c +++ 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, @@@ -1778,6 -1776,9 +1775,9 @@@ 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, @@@ -2086,7 -2087,7 +2086,7 @@@ 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, @@@ -2097,7 -2098,7 +2097,7 @@@ 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, @@@ -2110,7 -2111,7 +2110,7 @@@ 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; } @@@ -2354,7 -2353,7 +2354,7 @@@ 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,