Skip to content

Commit

Permalink
sha1_name: fix error message for @{u}
Browse files Browse the repository at this point in the history
Currently, when no (valid) upstream is configured for a branch, you get
an error like:

  $ git show @{u}
  error: No upstream configured for branch 'upstream-error'
  error: No upstream configured for branch 'upstream-error'
  fatal: ambiguous argument '@{u}': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

The "error: " line actually appears twice, and the rest of the error
message is useless.  In sha1_name.c:interpret_branch_name(), there is
really no point in processing further if @{u} couldn't be resolved, and
we might as well die() instead of returning an error().  After making
this change, you get:

  $ git show @{u}
  fatal: No upstream configured for branch 'upstream-error'

Also tweak a few tests in t1507 to expect this output.

This only turns error() that may be called after we know we are
dealing with an @{upstream} marker into die(), without touching
silent error returns "return -1" from the function.  Any caller that
wants to handle an error condition itself will not be hurt by this
change, unless they want to see the message from error() and then
exit silently without giving its own message, which needs to be
fixed anyway.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ramkumar Ramachandra authored and Junio C Hamano committed May 22, 2013
1 parent 9134a46 commit 17bf4ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
13 changes: 7 additions & 6 deletions sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,14 +1033,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
* points to something different than a branch.
*/
if (!upstream)
return error(_("HEAD does not point to a branch"));
die(_("HEAD does not point to a branch"));
if (!upstream->merge || !upstream->merge[0]->dst) {
if (!ref_exists(upstream->refname))
return error(_("No such branch: '%s'"), cp);
if (!upstream->merge)
return error(_("No upstream configured for branch '%s'"),
upstream->name);
return error(
die(_("No such branch: '%s'"), cp);
if (!upstream->merge) {
die(_("No upstream configured for branch '%s'"),
upstream->name);
}
die(
_("Upstream branch '%s' not stored as a remote-tracking branch"),
upstream->merge[0]->src);
}
Expand Down
15 changes: 5 additions & 10 deletions t/t1507-rev-parse-upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,31 @@ test_expect_success 'branch@{u} works when tracking a local branch' '

test_expect_success 'branch@{u} error message when no upstream' '
cat >expect <<-EOF &&
error: No upstream configured for branch ${sq}non-tracking${sq}
fatal: Needed a single revision
fatal: No upstream configured for branch ${sq}non-tracking${sq}
EOF
error_message non-tracking@{u} 2>actual &&
test_i18ncmp expect actual
'

test_expect_success '@{u} error message when no upstream' '
cat >expect <<-EOF &&
error: No upstream configured for branch ${sq}master${sq}
fatal: Needed a single revision
fatal: No upstream configured for branch ${sq}master${sq}
EOF
test_must_fail git rev-parse --verify @{u} 2>actual &&
test_i18ncmp expect actual
'

test_expect_success 'branch@{u} error message with misspelt branch' '
cat >expect <<-EOF &&
error: No such branch: ${sq}no-such-branch${sq}
fatal: Needed a single revision
fatal: No such branch: ${sq}no-such-branch${sq}
EOF
error_message no-such-branch@{u} 2>actual &&
test_i18ncmp expect actual
'

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

test_expect_success 'branch@{u} error message if upstream branch not fetched' '
cat >expect <<-EOF &&
error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
fatal: Needed a single revision
fatal: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
EOF
error_message bad-upstream@{u} 2>actual &&
test_i18ncmp expect actual
Expand Down

0 comments on commit 17bf4ff

Please sign in to comment.