Skip to contentSkip to conversation

add: Do not open editor if patch is empty

RFC PATCH In review Alexander Kuleshov 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 add: Do not open editor if patch is empty

If we'll run 'git add -e <path>' on a path which has no difference with the current index, empty editor will open. This patch prevents this behaviour and checks that patch is not empty before an editor with patch will be opened.

---
 builtin/add.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/add.c +2 -2
index ee370b0..4fc6b13 100644
@@ -209,13 +209,13 @@ 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 (stat(file, &st))
 		die_errno(_("Could not stat '%s'"), file);
 	if (!st.st_size)
 		die(_("Empty patch. Aborted."));
 
+	launch_editor(file, NULL, NULL);
+
 	child.git_cmd = 1;
 	child.argv = apply_argv;
 	if (run_command(&child))
Signature · 1 line
2.3.3.611.g09038fc.dirty
#1 lore raw
Quoted 13 lines · Alexander Kuleshov

If we'll run 'git add -e <path>' on a path which has no difference with the current index, empty editor will open. This patch prevents this behaviour and checks that patch is not empty before an editor with patch will be opened.

---

builtin/add.c +0 -0
index ee370b0..4fc6b13 100644
@@ -209,13 +209,13 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        if (run_diff_files(&rev, 0))

builtin/add.c static int edit_patch(int argc, const char **argv, const char *prefix) · line 217

Quoted 10 lines
builtin/add.c +1 -2
                die(_("Could not write patch"));
 
-       launch_editor(file, NULL, NULL);
-
        if (stat(file, &st))
                die_errno(_("Could not stat '%s'"), file);
        if (!st.st_size)
                die(_("Empty patch. Aborted."));
 
+       launch_editor(file, NULL, NULL);

But this breaks intended behavior[1] in which "git add -e" aborts with message "Empty patch" if the user deletes everything from the patch file in the editor.

[1]: c59cb03 (git-add: introduce --edit (to edit the diff vs. the index), 2009-04-08)

Quoted 5 lines
builtin/add.c +0 -1
        child.git_cmd = 1;
        child.argv = apply_argv;
        if (run_command(&child))
--

2.3.3.611.g09038fc.dirty