{"thread":{"id":"39950","subject":"[PATCH] git-add-interactive: edit current file in editor","startedAt":"2015-07-27T23:41:22Z","lastAt":"2015-07-29T19:05:02Z","messageCount":3,"participants":["Sina Siadat","Jacob Keller","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"266875","messageId":"1438040482-4599-1-git-send-email-siadat@gmail.com","threadId":"39950","inReplyTo":null,"subject":"[PATCH] git-add-interactive: edit current file in editor","fromName":"Sina Siadat","fromEmail":"siadat@gmail.com","sentAt":"2015-07-27T23:41:22Z","receivedAt":"2015-07-27T23:41:22Z","isPatch":true,"sender":{"key":"siadat@gmail.com","avatar":null},"body":"Adds a new option 'o' to the 'add -p' command that lets you open and edit the\ncurrent file.\n\nThe existing 'e' mode is used to manually edit the hunk.  The new 'o' option\nallows you to open and edit the file without having to quit the loop. The hunks\nare updated when the editing is done, and the user will be able to review the\nupdated hunks.  Without this option you would have to quit the loop, edit the\nfile, and execute 'add -p filename' again.\n\nI would appreciate it if you could let me know what you think about this\noption. I will write more tests if there is any interest at all.\n\nThank you. :)\n\n---\n Documentation/git-add.txt  |  1 +\n git-add--interactive.perl  | 11 ++++++++++-\n t/t3701-add-interactive.sh |  6 ++++++\n 3 files changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex fe5282f..6752eb0 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -312,6 +312,7 @@ patch::\n        K - leave this hunk undecided, see previous hunk\n        s - split the current hunk into smaller hunks\n        e - manually edit the current hunk\n+       o - open this file in editor\n        ? - print help\n +\n After deciding the fate for all hunks, if there is any hunk\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 77876d4..a44f3b3 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -1175,6 +1175,7 @@ k - leave this hunk undecided, see previous undecided hunk\n K - leave this hunk undecided, see previous hunk\n s - split the current hunk into smaller hunks\n e - manually edit the current hunk\n+o - open this file in editor\n ? - print help\n EOF\n }\n@@ -1359,7 +1360,7 @@ sub patch_update_file {\n \t\t   $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' :\n \t\t   ' this hunk'),\n \t\t  $patch_mode_flavour{TARGET},\n-\t\t  \" [y,n,q,a,d,/$other,?]? \";\n+\t\t  \" [y,n,q,a,d,o,/$other,?]? \";\n \t\tmy $line = prompt_single_character;\n \t\tlast unless defined $line;\n \t\tif ($line) {\n@@ -1378,6 +1379,14 @@ sub patch_update_file {\n \t\t\t\t}\n \t\t\t\tnext;\n \t\t\t}\n+\t\t\telsif ($line =~ /^o/) {\n+\t\t\t\tchomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));\n+\t\t\t\tsystem('sh', '-c', $editor.' \"$@\"', $editor, $path);\n+\t\t\t\t($head, @hunk) = parse_diff($path);\n+\t\t\t\t$num = scalar @hunk;\n+\t\t\t\t$ix = 0;\n+\t\t\t\tnext;\n+\t\t\t}\n \t\t\telsif ($other =~ /g/ && $line =~ /^g(.*)/) {\n \t\t\t\tmy $response = $1;\n \t\t\t\tmy $no = $ix > 10 ? $ix - 10 : 0;\ndiff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\nindex deae948..e5dd1c6 100755\n--- a/t/t3701-add-interactive.sh\n+++ b/t/t3701-add-interactive.sh\n@@ -98,6 +98,12 @@ test_expect_success 'dummy edit works' '\n \ttest_cmp expected diff\n '\n \n+test_expect_success 'dummy open works' '\n+\t(echo o; echo a) | git add -p &&\n+\tgit diff > diff &&\n+\ttest_cmp expected diff\n+'\n+\n test_expect_success 'setup patch' '\n cat >patch <<EOF\n @@ -1,1 +1,4 @@\n-- \n2.5.0.rc3.2.g6f9504c.dirty\n"},{"id":"266878","messageId":"CA+P7+xptro_1nePQbQtGtRc-a9=swXvZiERDCiQc=NReUsV53Q@mail.gmail.com","threadId":"39950","inReplyTo":"1438040482-4599-1-git-send-email-siadat@gmail.com","subject":"Re: [PATCH] git-add-interactive: edit current file in editor","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2015-07-28T05:12:58Z","receivedAt":"2015-07-28T05:12:58Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Jul 27, 2015 at 4:41 PM, Sina Siadat <siadat@gmail.com> wrote:\n> Adds a new option 'o' to the 'add -p' command that lets you open and edit the\n> current file.\n>\n> The existing 'e' mode is used to manually edit the hunk.  The new 'o' option\n> allows you to open and edit the file without having to quit the loop. The hunks\n> are updated when the editing is done, and the user will be able to review the\n> updated hunks.  Without this option you would have to quit the loop, edit the\n> file, and execute 'add -p filename' again.\n>\n> I would appreciate it if you could let me know what you think about this\n> option. I will write more tests if there is any interest at all.\n>\n> Thank you. :)\n>\n\nAbsolutely want and would use this change every day. My standard model\nof commit flow is:\n\nhack commit hack commit hack commit\n\nrest head\n\nadd -i ; commit\n\nadd -i ; commit\n\nand sometimes I end up with code that I need to actually change, not\njust edit diff hunks for, but change in the final file. This would\nmake my flow way easier, especially as I could manage hunks while\nediting files.\n\n\nRegards,\nJake\n"},{"id":"267090","messageId":"CAPig+cRRda=DVGAqpUjOsFk9Fqjqxi-apvWLuEW5xK1XCu5_+g@mail.gmail.com","threadId":"39950","inReplyTo":"1438040482-4599-1-git-send-email-siadat@gmail.com","subject":"Re: [PATCH] git-add-interactive: edit current file in editor","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-07-29T19:05:02Z","receivedAt":"2015-07-29T19:05:02Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"Aside from whether or not this change is desirable, see a few pointers\nbelow to improve the patch...\n\nOn Monday, July 27, 2015, Sina Siadat <siadat@gmail.com> wrote:\n> Adds a new option 'o' to the 'add -p' command that lets you open and edit the\n> current file.\n\nImperative mood: \"Add a new option...\"\n\n> The existing 'e' mode is used to manually edit the hunk.  The new 'o' option\n> allows you to open and edit the file without having to quit the loop. The hunks\n> are updated when the editing is done, and the user will be able to review the\n> updated hunks.  Without this option you would have to quit the loop, edit the\n> file, and execute 'add -p filename' again.\n\nThis descriptive material belongs in the commit message. Good.\n\n> I would appreciate it if you could let me know what you think about this\n> option. I will write more tests if there is any interest at all.\n\nThis, however, is commentary, which, while useful as part of the\nsubmission process, does not belong in the commit message. Therefore,\nit should be placed below the \"---\" line just before the diffstat.\n\n> Thank you. :)\n\nMissing sign-off. See Documentation/SubmittingPatches.\n\nMore below...\n\n> ---\n> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\n> index deae948..e5dd1c6 100755\n> --- a/t/t3701-add-interactive.sh\n> +++ b/t/t3701-add-interactive.sh\n> @@ -98,6 +98,12 @@ test_expect_success 'dummy edit works' '\n>         test_cmp expected diff\n>  '\n>\n> +test_expect_success 'dummy open works' '\n> +       (echo o; echo a) | git add -p &&\n\nSome alternatives, which may or may not read better, but at least\navoid a process creation or two:\n\n    { echo o; echo a; } | git add -p &&\n\n    printf \"%s\\n\" o a | git add -p &&\n\n    printf \"o\\na\\n\" | git add -p &&\n\nThose are just suggestions; not necessarily a request for change.\n\n> +       git diff > diff &&\n\nStyle: >diff\n\n> +       test_cmp expected diff\n> +'\n> +\n>  test_expect_success 'setup patch' '\n>  cat >patch <<EOF\n>  @@ -1,1 +1,4 @@\n> --\n> 2.5.0.rc3.2.g6f9504c.dirty\n"}]}