Merge branch 'km/branch-get-push-while-detached'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Jan 2017 23:12:14 +0000 (15:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jan 2017 23:12:14 +0000 (15:12 -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

remote.c
t/t1514-rev-parse-push.sh
index ad6c5424edab2ae15ac17bfcf12ac4ee93b5aa3f..d5eaec73742e74738c522cdc36ba9bf811b158b2 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1716,9 +1716,6 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
 {
        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 +1775,9 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *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;
index 7214f5b33fa41fbb685e572ca24a0cb11337d251..623a32aa6e323d11267cb89af62d42c325a4dd75 100755 (executable)
@@ -60,4 +60,10 @@ test_expect_success '@{push} with push refspecs' '
        resolve topic@{push} refs/remotes/origin/magic/topic
 '
 
+test_expect_success 'resolving @{push} fails with a detached HEAD' '
+       git checkout HEAD^0 &&
+       test_when_finished "git checkout -" &&
+       test_must_fail git rev-parse @{push}
+'
+
 test_done