Skip to content

Commit cb64800

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit cb64800

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
207207
if (run_diff_files(&rev, 0))
208208
die(_("Could not write patch"));
209209

210-
launch_editor(file, NULL, NULL);
210+
if (launch_editor(file, NULL, NULL))
211+
die(_("editing patch failed"));
211212

212213
if (stat(file, &st))
213214
die_errno(_("Could not stat '%s'"), file);

t/t3702-add-edit.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,11 @@ test_expect_success 'add -e' '
118118
119119
'
120120

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+
121128
test_done

0 commit comments

Comments
 (0)