{"thread":{"id":"39164","subject":"[PATCH RFC] add: Do not open editor if patch is empty","startedAt":"2015-04-26T17:03:40Z","lastAt":"2015-04-26T18:39:06Z","messageCount":2,"participants":["Alexander Kuleshov","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"260035","messageId":"1430067820-3349-1-git-send-email-kuleshovmail@gmail.com","threadId":"39164","inReplyTo":null,"subject":"[PATCH RFC] add: Do not open editor if patch is empty","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-04-26T17:03:40Z","receivedAt":"2015-04-26T17:03:40Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"If we'll run 'git add -e <path>' on a path which has no\ndifference with the current index, empty editor will open. This\npatch prevents this behaviour and checks that patch is not empty\nbefore an editor with patch will be opened.\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n builtin/add.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex ee370b0..4fc6b13 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -209,13 +209,13 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \tif (run_diff_files(&rev, 0))\n \t\tdie(_(\"Could not write patch\"));\n \n-\tlaunch_editor(file, NULL, NULL);\n-\n \tif (stat(file, &st))\n \t\tdie_errno(_(\"Could not stat '%s'\"), file);\n \tif (!st.st_size)\n \t\tdie(_(\"Empty patch. Aborted.\"));\n \n+\tlaunch_editor(file, NULL, NULL);\n+\n \tchild.git_cmd = 1;\n \tchild.argv = apply_argv;\n \tif (run_command(&child))\n-- \n2.3.3.611.g09038fc.dirty\n"},{"id":"260037","messageId":"CAPig+cTMWe4gnuMrx-aP1Zu+qr6UqmHFmJj2JoahtuxcDGLTQg@mail.gmail.com","threadId":"39164","inReplyTo":"1430067820-3349-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH RFC] add: Do not open editor if patch is empty","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-04-26T18:39:06Z","receivedAt":"2015-04-26T18:39:06Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 26, 2015 at 1:03 PM, Alexander Kuleshov\n<kuleshovmail@gmail.com> wrote:\n> If we'll run 'git add -e <path>' on a path which has no\n> difference with the current index, empty editor will open. This\n> patch prevents this behaviour and checks that patch is not empty\n> before an editor with patch will be opened.\n>\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n> diff --git a/builtin/add.c b/builtin/add.c\n> index ee370b0..4fc6b13 100644\n> --- a/builtin/add.c\n> +++ b/builtin/add.c\n> @@ -209,13 +209,13 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n>         if (run_diff_files(&rev, 0))\n>                 die(_(\"Could not write patch\"));\n>\n> -       launch_editor(file, NULL, NULL);\n> -\n>         if (stat(file, &st))\n>                 die_errno(_(\"Could not stat '%s'\"), file);\n>         if (!st.st_size)\n>                 die(_(\"Empty patch. Aborted.\"));\n>\n> +       launch_editor(file, NULL, NULL);\n\nBut this breaks intended behavior[1] in which \"git add -e\" aborts with\nmessage \"Empty patch\" if the user deletes everything from the patch\nfile in the editor.\n\n[1]: c59cb03 (git-add: introduce --edit (to edit the diff vs. the\nindex), 2009-04-08)\n\n>         child.git_cmd = 1;\n>         child.argv = apply_argv;\n>         if (run_command(&child))\n> --\n> 2.3.3.611.g09038fc.dirty\n"}]}