git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] add -p: improve error messages

From
PWPhillip Wood <phillip.wood@talktalk.net>
Date
Feb 13, 2018, 10:32 UTC
Message-ID
<20180213103241.6789-4-phillip.wood@talktalk.net>
In-Reply-To
<20180213103241.6789-1-phillip.wood@talktalk.net>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

If the user presses a key that isn't currently active then explain why it isn't active rather than just listing all the keys. It already did this for some keys, this patch does the same for the those that weren't already handled.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 git-add--interactive.perl | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 79ab36aacf84ed329a9d50886b98bb4ef8b8e312..d9d8ff3090e914421ab67071117789f6b3554475 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1437,8 +1437,12 @@ sub patch_update_file {
 				}
 				next;
 			}
-			elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
+			elsif ($line =~ /^g(.*)/) {
 				my $response = $1;
+				unless ($other =~ /g/) {
+					error_msg __("No other hunks to goto\n");
+					next;
+				}
 				my $no = $ix > 10 ? $ix - 10 : 0;
 				while ($response eq '') {
 					$no = display_hunks(\@hunk, $no);
@@ -1556,7 +1560,11 @@ sub patch_update_file {
 					next;
 				}
 			}
-			elsif ($other =~ /s/ && $line =~ /^s/) {
+			elsif ($line =~ /^s/) {
+				unless ($other =~ /s/) {
+					error_msg __("Sorry, cannot split this hunk\n");
+					next;
+				}
 				my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
 				if (1 < @split) {
 					print colored $header_color, sprintf(
@@ -1568,7 +1576,11 @@ sub patch_update_file {
 				$num = scalar @hunk;
 				next;
 			}
-			elsif ($other =~ /e/ && $line =~ /^e/) {
+			elsif ($line =~ /^e/) {
+				unless ($other =~ /e/) {
+					error_msg __("Sorry, cannot edit this hunk\n");
+					next;
+				}
 				my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
 				if (defined $newhunk) {
 					splice @hunk, $ix, 1, $newhunk;
-- 
2.16.1
Previous: Phillip WoodNext: Phillip Wood
Message 2 of 9 in “add -p: improve help messages”
  1. 0/3 add -p: improve help messagesPhillip Wood, Feb 13, 2018
  2. 3/3 add -p: improve error messagesPhillip Wood, Feb 13, 2018
  3. 1/3 add -p: only display help for active keysPhillip Wood, Feb 13, 2018
  4. 2/3 add -p: Only bind search key if there's more than one hunkPhillip Wood, Feb 13, 2018
  5. add -p: fix 2.17.0-rc* regression due to moved codeÆvar Arnfjörð Bjarmason, Mar 31, 2018
  6. add -p: fix 2.17.0-rc* regression due to moved codeÆvar Arnfjörð Bjarmason, Mar 31, 2018
  7. Phillip WoodMar 31, 2018
  8. Ævar Arnfjörð BjarmasonMar 31, 2018
  9. Junio C HamanoApr 1, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.