Skip to content

Commit cbd3a01

Browse files
moygitster
authored andcommitted
git add -p: new "quit" command at the prompt.
There's already 'd' to stop staging hunks in a file, but no explicit command to stop the interactive staging (for the current files and the remaining ones). Of course you can do 'd' and then ^C, but it would be more intuitive to allow 'quit' action. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3bd1bb3 commit cbd3a01

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Documentation/git-add.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ patch::
245245

246246
y - stage this hunk
247247
n - do not stage this hunk
248+
q - quite, do not stage this hunk nor any of the remaining ones
248249
a - stage this and all the remaining hunks in the file
249250
d - do not stage this hunk nor any of the remaining hunks in the file
250251
j - leave this hunk undecided, see next undecided hunk

git-add--interactive.perl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ sub help_patch_cmd {
890890
print colored $help_color, <<\EOF ;
891891
y - stage this hunk
892892
n - do not stage this hunk
893+
q - quit, do not stage this hunk nor any of the remaining ones
893894
a - stage this and all the remaining hunks in the file
894895
d - do not stage this hunk nor any of the remaining hunks in the file
895896
g - select a hunk to go to
@@ -926,7 +927,7 @@ sub patch_update_cmd {
926927
@mods);
927928
}
928929
for (@them) {
929-
patch_update_file($_->{VALUE});
930+
return 0 if patch_update_file($_->{VALUE});
930931
}
931932
}
932933

@@ -972,6 +973,7 @@ sub display_hunks {
972973
}
973974

974975
sub patch_update_file {
976+
my $quit = 0;
975977
my ($ix, $num);
976978
my $path = shift;
977979
my ($head, @hunk) = parse_diff($path);
@@ -1002,6 +1004,11 @@ sub patch_update_file {
10021004
$_->{USE} = 0 foreach ($mode, @hunk);
10031005
last;
10041006
}
1007+
elsif ($line =~ /^q/i) {
1008+
$_->{USE} = 0 foreach ($mode, @hunk);
1009+
$quit = 1;
1010+
last;
1011+
}
10051012
else {
10061013
help_patch_cmd('');
10071014
next;
@@ -1109,6 +1116,16 @@ sub patch_update_file {
11091116
}
11101117
next;
11111118
}
1119+
elsif ($line =~ /^q/i) {
1120+
while ($ix < $num) {
1121+
if (!defined $hunk[$ix]{USE}) {
1122+
$hunk[$ix]{USE} = 0;
1123+
}
1124+
$ix++;
1125+
}
1126+
$quit = 1;
1127+
next;
1128+
}
11121129
elsif ($line =~ m|^/(.*)|) {
11131130
my $regex = $1;
11141131
if ($1 eq "") {
@@ -1235,6 +1252,7 @@ sub patch_update_file {
12351252
}
12361253

12371254
print "\n";
1255+
return $quit;
12381256
}
12391257

12401258
sub diff_cmd {

0 commit comments

Comments
 (0)