Skip to content

Commit b3bf469

Browse files
committed
Merge branch 'rr/die-on-missing-upstream' into maint
When a reflog notation is used for implicit "current branch", we did not say which branch, and worse said "branch ''". * rr/die-on-missing-upstream: sha1_name: fix error message for @{<N>}, @{<date>} sha1_name: fix error message for @{u}
2 parents dfc6b04 + 305ebea commit b3bf469

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

sha1_name.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,21 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
517517
}
518518
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
519519
&co_time, &co_tz, &co_cnt)) {
520+
if (!len) {
521+
if (!prefixcmp(real_ref, "refs/heads/")) {
522+
str = real_ref + 11;
523+
len = strlen(real_ref + 11);
524+
} else {
525+
/* detached HEAD */
526+
str = "HEAD";
527+
len = 4;
528+
}
529+
}
520530
if (at_time)
521531
warning("Log for '%.*s' only goes "
522532
"back to %s.", len, str,
523533
show_date(co_time, co_tz, DATE_RFC2822));
524534
else {
525-
free(real_ref);
526535
die("Log for '%.*s' only has %d entries.",
527536
len, str, co_cnt);
528537
}
@@ -1033,14 +1042,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
10331042
* points to something different than a branch.
10341043
*/
10351044
if (!upstream)
1036-
return error(_("HEAD does not point to a branch"));
1045+
die(_("HEAD does not point to a branch"));
10371046
if (!upstream->merge || !upstream->merge[0]->dst) {
10381047
if (!ref_exists(upstream->refname))
1039-
return error(_("No such branch: '%s'"), cp);
1040-
if (!upstream->merge)
1041-
return error(_("No upstream configured for branch '%s'"),
1042-
upstream->name);
1043-
return error(
1048+
die(_("No such branch: '%s'"), cp);
1049+
if (!upstream->merge) {
1050+
die(_("No upstream configured for branch '%s'"),
1051+
upstream->name);
1052+
}
1053+
die(
10441054
_("Upstream branch '%s' not stored as a remote-tracking branch"),
10451055
upstream->merge[0]->src);
10461056
}

t/t1507-rev-parse-upstream.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,35 +129,31 @@ test_expect_success 'branch@{u} works when tracking a local branch' '
129129

130130
test_expect_success 'branch@{u} error message when no upstream' '
131131
cat >expect <<-EOF &&
132-
error: No upstream configured for branch ${sq}non-tracking${sq}
133-
fatal: Needed a single revision
132+
fatal: No upstream configured for branch ${sq}non-tracking${sq}
134133
EOF
135134
error_message non-tracking@{u} 2>actual &&
136135
test_i18ncmp expect actual
137136
'
138137

139138
test_expect_success '@{u} error message when no upstream' '
140139
cat >expect <<-EOF &&
141-
error: No upstream configured for branch ${sq}master${sq}
142-
fatal: Needed a single revision
140+
fatal: No upstream configured for branch ${sq}master${sq}
143141
EOF
144142
test_must_fail git rev-parse --verify @{u} 2>actual &&
145143
test_i18ncmp expect actual
146144
'
147145

148146
test_expect_success 'branch@{u} error message with misspelt branch' '
149147
cat >expect <<-EOF &&
150-
error: No such branch: ${sq}no-such-branch${sq}
151-
fatal: Needed a single revision
148+
fatal: No such branch: ${sq}no-such-branch${sq}
152149
EOF
153150
error_message no-such-branch@{u} 2>actual &&
154151
test_i18ncmp expect actual
155152
'
156153

157154
test_expect_success '@{u} error message when not on a branch' '
158155
cat >expect <<-EOF &&
159-
error: HEAD does not point to a branch
160-
fatal: Needed a single revision
156+
fatal: HEAD does not point to a branch
161157
EOF
162158
git checkout HEAD^0 &&
163159
test_must_fail git rev-parse --verify @{u} 2>actual &&
@@ -166,8 +162,7 @@ test_expect_success '@{u} error message when not on a branch' '
166162

167163
test_expect_success 'branch@{u} error message if upstream branch not fetched' '
168164
cat >expect <<-EOF &&
169-
error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
170-
fatal: Needed a single revision
165+
fatal: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
171166
EOF
172167
error_message bad-upstream@{u} 2>actual &&
173168
test_i18ncmp expect actual

0 commit comments

Comments
 (0)