]> granicus.if.org Git - git/commitdiff
add: check return value of launch_editor
authorJeff King <peff@peff.net>
Wed, 13 May 2015 01:21:58 +0000 (21:21 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 May 2015 03:25:08 +0000 (20:25 -0700)
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>
builtin/add.c
t/t3702-add-edit.sh

index 459208a326cd4cebfa813168d81a06c27fc54fc5..1c7436589e3b44356da9eb319ddc6d75e38f9b68 100644 (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);
index 4ee47cc9a862cdbe8c63bc9d4ebbe46ff3c344bc..3cb74ca296d141a6bd248e527680f5f217608ca7 100755 (executable)
@@ -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