From: Jeff King Date: Wed, 13 May 2015 01:21:58 +0000 (-0400) Subject: add: check return value of launch_editor X-Git-Tag: v2.4.3~20^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb64800d83ace6fecb8701151cfdb6ed0712702c;p=thirdparty%2Fgit.git 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 Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/builtin/add.c b/builtin/add.c index 459208a326..1c7436589e 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -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); diff --git a/t/t3702-add-edit.sh b/t/t3702-add-edit.sh index 4ee47cc9a8..3cb74ca296 100755 --- a/t/t3702-add-edit.sh +++ b/t/t3702-add-edit.sh @@ -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