git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 1/4] symbolic-ref: propagate error code from create_symref()
Date: Sun, 20 Dec 2015 02:27:18 -0500	[thread overview]
Message-ID: <20151220072718.GA30662@sigill.intra.peff.net> (raw)
In-Reply-To: <20151220072637.GA22102@sigill.intra.peff.net>

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>
---
 builtin/symbolic-ref.c  | 2 +-
 t/t1401-symbolic-ref.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index ce0fde7..9c29a64 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -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);
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index 20b022a..fbb4835 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -92,4 +92,10 @@ test_expect_success LONG_REF 'we can parse long symbolic ref' '
 	test_cmp expect actual
 '
 
+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
-- 
2.7.0.rc1.350.g9acc0f4

  reply	other threads:[~2015-12-20  7:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-20  7:26 [PATCH 0/4] improve symbolic-ref robustness Jeff King
2015-12-20  7:27 ` Jeff King [this message]
2015-12-20  7:27 ` [PATCH 2/4] t1401: test reflog creation for git-symbolic-ref Jeff King
2015-12-20  7:29 ` [PATCH 3/4] create_symref: modernize variable names Jeff King
2015-12-28  8:20   ` Michael Haggerty
2015-12-29  5:02     ` Jeff King
2015-12-20  7:34 ` [PATCH 4/4] create_symref: use existing ref-lock code Jeff King
2015-12-21 20:50   ` Junio C Hamano
2015-12-22  0:58     ` Jeff King
2015-12-28  9:45   ` Michael Haggerty
2015-12-29  5:02     ` Jeff King
2015-12-29  5:41       ` Jeff King
2015-12-29  5:55 ` [PATCH v2 0/3] improve symbolic-ref robustness Jeff King
2015-12-29  5:56   ` [PATCH 1/3] create_symref: modernize variable names Jeff King
2015-12-29  5:57   ` [PATCH 2/3] create_symref: use existing ref-lock code Jeff King
2015-12-29  5:57   ` [PATCH 3/3] create_symref: write reflog while holding lock Jeff King
2015-12-29  6:00   ` [RFC/PATCH 4/3] create_symref: drop support for writing symbolic links Jeff King
2015-12-29  6:03     ` Jeff King
2015-12-29 18:32     ` Junio C Hamano
2015-12-30  6:53       ` Jeff King
2015-12-30  6:56         ` Jeff King
2015-12-29  8:25   ` [PATCH v2 0/3] improve symbolic-ref robustness Michael Haggerty
2015-12-29 18:35     ` Junio C Hamano
2015-12-29 21:24   ` Junio C Hamano
2015-12-30  6:57     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151220072718.GA30662@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).