add: check return value of launch_editor

When running "add -e", if launching the editor fails, we do
not notice and continue as if the output is what the user
asked for. The likely case is that the editor did not touch
the contents at all, and we end up adding everything.

Reported-by: Russ Cox <rsc@golang.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2015-05-12 21:21:58 -04:00 committed by Junio C Hamano
parent 282616c72d
commit cb64800d83
2 changed files with 9 additions and 1 deletions

View File

@ -207,7 +207,8 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
if (run_diff_files(&rev, 0))
die(_("Could not write patch"));
launch_editor(file, NULL, NULL);
if (launch_editor(file, NULL, NULL))
die(_("editing patch failed"));
if (stat(file, &st))
die_errno(_("Could not stat '%s'"), file);

View File

@ -118,4 +118,11 @@ test_expect_success 'add -e' '
'
test_expect_success 'add -e notices editor failure' '
git reset --hard &&
echo change >>file &&
test_must_fail env GIT_EDITOR=false git add -e &&
test_expect_code 1 git diff --exit-code
'
test_done