Skip to content

Commit 3e4068e

Browse files
peffgitster
authored andcommitted
symbolic-ref: propagate error code from create_symref()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2558fb commit 3e4068e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

builtin/symbolic-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
6767
if (!strcmp(argv[0], "HEAD") &&
6868
!starts_with(argv[1], "refs/"))
6969
die("Refusing to point HEAD outside of refs/");
70-
create_symref(argv[0], argv[1], msg);
70+
ret = !!create_symref(argv[0], argv[1], msg);
7171
break;
7272
default:
7373
usage_with_options(git_symbolic_ref_usage, options);

t/t1401-symbolic-ref.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ test_expect_success 'symbolic-ref fails to delete real ref' '
6363
'
6464
reset_to_sane
6565

66+
test_expect_success 'symbolic-ref reports failure in exit code' '
67+
test_when_finished "rm -f .git/HEAD.lock" &&
68+
>.git/HEAD.lock &&
69+
test_must_fail git symbolic-ref HEAD refs/heads/whatever
70+
'
71+
6672
test_done

0 commit comments

Comments
 (0)