Skip to content

Commit f5f55a1

Browse files
committed
Merge branch 'km/branch-get-push-while-detached' into maint
"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
2 parents 2b3f61d + b10731f commit f5f55a1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

remote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,9 +1716,6 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
17161716
{
17171717
struct remote *remote;
17181718

1719-
if (!branch)
1720-
return error_buf(err, _("HEAD does not point to a branch"));
1721-
17221719
remote = remote_get(pushremote_for_branch(branch, NULL));
17231720
if (!remote)
17241721
return error_buf(err,
@@ -1778,6 +1775,9 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
17781775

17791776
const char *branch_get_push(struct branch *branch, struct strbuf *err)
17801777
{
1778+
if (!branch)
1779+
return error_buf(err, _("HEAD does not point to a branch"));
1780+
17811781
if (!branch->push_tracking_ref)
17821782
branch->push_tracking_ref = branch_get_push_1(branch, err);
17831783
return branch->push_tracking_ref;

t/t1514-rev-parse-push.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ test_expect_success '@{push} with push refspecs' '
6060
resolve topic@{push} refs/remotes/origin/magic/topic
6161
'
6262

63+
test_expect_success 'resolving @{push} fails with a detached HEAD' '
64+
git checkout HEAD^0 &&
65+
test_when_finished "git checkout -" &&
66+
test_must_fail git rev-parse @{push}
67+
'
68+
6369
test_done

0 commit comments

Comments
 (0)