All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-add-interactive: edit current file in editor
@ 2015-07-27 23:41 Sina Siadat
  2015-07-28  5:12 ` Jacob Keller
  2015-07-29 19:05 ` Eric Sunshine
  0 siblings, 2 replies; 3+ messages in thread
From: Sina Siadat @ 2015-07-27 23:41 UTC (permalink / raw)
  To: git; +Cc: Sina Siadat

Adds a new option 'o' to the 'add -p' command that lets you open and edit the
current file.

The existing 'e' mode is used to manually edit the hunk.  The new 'o' option
allows you to open and edit the file without having to quit the loop. The hunks
are updated when the editing is done, and the user will be able to review the
updated hunks.  Without this option you would have to quit the loop, edit the
file, and execute 'add -p filename' again.

I would appreciate it if you could let me know what you think about this
option. I will write more tests if there is any interest at all.

Thank you. :)

---
 Documentation/git-add.txt  |  1 +
 git-add--interactive.perl  | 11 ++++++++++-
 t/t3701-add-interactive.sh |  6 ++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index fe5282f..6752eb0 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -312,6 +312,7 @@ patch::
        K - leave this hunk undecided, see previous hunk
        s - split the current hunk into smaller hunks
        e - manually edit the current hunk
+       o - open this file in editor
        ? - print help
 +
 After deciding the fate for all hunks, if there is any hunk
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 77876d4..a44f3b3 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1175,6 +1175,7 @@ k - leave this hunk undecided, see previous undecided hunk
 K - leave this hunk undecided, see previous hunk
 s - split the current hunk into smaller hunks
 e - manually edit the current hunk
+o - open this file in editor
 ? - print help
 EOF
 }
@@ -1359,7 +1360,7 @@ sub patch_update_file {
 		   $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' :
 		   ' this hunk'),
 		  $patch_mode_flavour{TARGET},
-		  " [y,n,q,a,d,/$other,?]? ";
+		  " [y,n,q,a,d,o,/$other,?]? ";
 		my $line = prompt_single_character;
 		last unless defined $line;
 		if ($line) {
@@ -1378,6 +1379,14 @@ sub patch_update_file {
 				}
 				next;
 			}
+			elsif ($line =~ /^o/) {
+				chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));
+				system('sh', '-c', $editor.' "$@"', $editor, $path);
+				($head, @hunk) = parse_diff($path);
+				$num = scalar @hunk;
+				$ix = 0;
+				next;
+			}
 			elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
 				my $response = $1;
 				my $no = $ix > 10 ? $ix - 10 : 0;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index deae948..e5dd1c6 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -98,6 +98,12 @@ test_expect_success 'dummy edit works' '
 	test_cmp expected diff
 '
 
+test_expect_success 'dummy open works' '
+	(echo o; echo a) | git add -p &&
+	git diff > diff &&
+	test_cmp expected diff
+'
+
 test_expect_success 'setup patch' '
 cat >patch <<EOF
 @@ -1,1 +1,4 @@
-- 
2.5.0.rc3.2.g6f9504c.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] git-add-interactive: edit current file in editor
  2015-07-27 23:41 [PATCH] git-add-interactive: edit current file in editor Sina Siadat
@ 2015-07-28  5:12 ` Jacob Keller
  2015-07-29 19:05 ` Eric Sunshine
  1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2015-07-28  5:12 UTC (permalink / raw)
  To: Sina Siadat; +Cc: Git List

On Mon, Jul 27, 2015 at 4:41 PM, Sina Siadat <siadat@gmail.com> wrote:
> Adds a new option 'o' to the 'add -p' command that lets you open and edit the
> current file.
>
> The existing 'e' mode is used to manually edit the hunk.  The new 'o' option
> allows you to open and edit the file without having to quit the loop. The hunks
> are updated when the editing is done, and the user will be able to review the
> updated hunks.  Without this option you would have to quit the loop, edit the
> file, and execute 'add -p filename' again.
>
> I would appreciate it if you could let me know what you think about this
> option. I will write more tests if there is any interest at all.
>
> Thank you. :)
>

Absolutely want and would use this change every day. My standard model
of commit flow is:

hack commit hack commit hack commit

rest head

add -i ; commit

add -i ; commit

and sometimes I end up with code that I need to actually change, not
just edit diff hunks for, but change in the final file. This would
make my flow way easier, especially as I could manage hunks while
editing files.


Regards,
Jake

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] git-add-interactive: edit current file in editor
  2015-07-27 23:41 [PATCH] git-add-interactive: edit current file in editor Sina Siadat
  2015-07-28  5:12 ` Jacob Keller
@ 2015-07-29 19:05 ` Eric Sunshine
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Sunshine @ 2015-07-29 19:05 UTC (permalink / raw)
  To: Sina Siadat; +Cc: git

Aside from whether or not this change is desirable, see a few pointers
below to improve the patch...

On Monday, July 27, 2015, Sina Siadat <siadat@gmail.com> wrote:
> Adds a new option 'o' to the 'add -p' command that lets you open and edit the
> current file.

Imperative mood: "Add a new option..."

> The existing 'e' mode is used to manually edit the hunk.  The new 'o' option
> allows you to open and edit the file without having to quit the loop. The hunks
> are updated when the editing is done, and the user will be able to review the
> updated hunks.  Without this option you would have to quit the loop, edit the
> file, and execute 'add -p filename' again.

This descriptive material belongs in the commit message. Good.

> I would appreciate it if you could let me know what you think about this
> option. I will write more tests if there is any interest at all.

This, however, is commentary, which, while useful as part of the
submission process, does not belong in the commit message. Therefore,
it should be placed below the "---" line just before the diffstat.

> Thank you. :)

Missing sign-off. See Documentation/SubmittingPatches.

More below...

> ---
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index deae948..e5dd1c6 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -98,6 +98,12 @@ test_expect_success 'dummy edit works' '
>         test_cmp expected diff
>  '
>
> +test_expect_success 'dummy open works' '
> +       (echo o; echo a) | git add -p &&

Some alternatives, which may or may not read better, but at least
avoid a process creation or two:

    { echo o; echo a; } | git add -p &&

    printf "%s\n" o a | git add -p &&

    printf "o\na\n" | git add -p &&

Those are just suggestions; not necessarily a request for change.

> +       git diff > diff &&

Style: >diff

> +       test_cmp expected diff
> +'
> +
>  test_expect_success 'setup patch' '
>  cat >patch <<EOF
>  @@ -1,1 +1,4 @@
> --
> 2.5.0.rc3.2.g6f9504c.dirty

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-29 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 23:41 [PATCH] git-add-interactive: edit current file in editor Sina Siadat
2015-07-28  5:12 ` Jacob Keller
2015-07-29 19:05 ` Eric Sunshine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.