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>

Jeff King committed May 12, 2015 at 21:21 UTC cb64800d83ace6fecb8701151cfdb6ed0712702c
2 files changed +9 -1
builtin/add.c
+2 -1
@@ -207,7 +207,8 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
207 if (run_diff_files(&rev, 0))
208 die(_("Could not write patch"));
209
210 - launch_editor(file, NULL, NULL);
210 + if (launch_editor(file, NULL, NULL))
211 + die(_("editing patch failed"));
212
213 if (stat(file, &st))
214 die_errno(_("Could not stat '%s'"), file);
t/t3702-add-edit.sh
+7
@@ -118,4 +118,11 @@ test_expect_success 'add -e' '
118
119 '
120
121 +test_expect_success 'add -e notices editor failure' '
122 + git reset --hard &&
123 + echo change >>file &&
124 + test_must_fail env GIT_EDITOR=false git add -e &&
125 + test_expect_code 1 git diff --exit-code
126 +'
127 +
128 test_done