Skip to content

Commit

Permalink
symbolic-ref: propagate error code from create_symref()
Browse files Browse the repository at this point in the history
If create_symref() fails, git-symbolic-ref will still exit
with code 0, and our caller has no idea that the command did
nothing.

This appears to have been broken since the beginning of time
(e.g., it is not a regression where create_symref() stopped
calling die() or something similar).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 21, 2015
1 parent a2558fb commit 3e4068e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/symbolic-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
if (!strcmp(argv[0], "HEAD") &&
!starts_with(argv[1], "refs/"))
die("Refusing to point HEAD outside of refs/");
create_symref(argv[0], argv[1], msg);
ret = !!create_symref(argv[0], argv[1], msg);
break;
default:
usage_with_options(git_symbolic_ref_usage, options);
Expand Down
6 changes: 6 additions & 0 deletions t/t1401-symbolic-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ test_expect_success 'symbolic-ref fails to delete real ref' '
'
reset_to_sane

test_expect_success 'symbolic-ref reports failure in exit code' '
test_when_finished "rm -f .git/HEAD.lock" &&
>.git/HEAD.lock &&
test_must_fail git symbolic-ref HEAD refs/heads/whatever
'

test_done

0 comments on commit 3e4068e

Please sign in to comment.