6 my $repo = Git
->repository();
8 my $menu_use_color = $repo->get_colorbool('color.interactive');
9 my ($prompt_color, $header_color, $help_color) =
11 $repo->get_color('color.interactive.prompt', 'bold blue'),
12 $repo->get_color('color.interactive.header', 'bold'),
13 $repo->get_color('color.interactive.help', 'red bold'),
16 if ($menu_use_color) {
17 my $help_color_spec = $repo->config('color.interactive.help');
18 $error_color = $repo->get_color('color.interactive.error',
22 my $diff_use_color = $repo->get_colorbool('color.diff');
23 my ($fraginfo_color) =
25 $repo->get_color('color.diff.frag', 'cyan'),
27 my ($diff_plain_color) =
29 $repo->get_color('color.diff.plain', ''),
31 my ($diff_old_color) =
33 $repo->get_color('color.diff.old', 'red'),
35 my ($diff_new_color) =
37 $repo->get_color('color.diff.new', 'green'),
40 my $normal_color = $repo->get_color("", "reset");
45 if ($repo->config_bool("interactive.singlekey")) {
47 require Term
::ReadKey
;
48 Term
::ReadKey
->import;
55 my $string = join("", @_);
58 # Put a color code at the beginning of each line, a reset at the end
59 # color after newlines that are not at the end of the string
60 $string =~ s/(\n+)(.)/$1$color$2/g;
61 # reset before newlines
62 $string =~ s/(\n+)/$normal_color$1/g;
63 # codes at beginning and end (if necessary):
64 $string =~ s/^/$color/;
65 $string =~ s/$/$normal_color/ unless $string =~ /\n$/;
70 # command line options
74 if ($^O
eq 'MSWin32' || $^O
eq 'msys') {
75 my @invalid = grep {m/[":*]/} @_;
76 die "$^O does not support: @invalid\n" if @invalid;
77 my @args = map { m/ /o ?
"\"$_\"": $_ } @_;
81 open($fh, '-|', @_) or die;
86 my ($GIT_DIR) = run_cmd_pipe
(qw(git rev-parse --git-dir));
88 if (!defined $GIT_DIR) {
89 exit(1); # rev-parse would have already said "not a git repo"
95 open $fh, 'git update-index --refresh |'
98 ;# ignore 'needs update'
108 run_cmd_pipe
(qw(git ls-files --others --exclude-standard --), @ARGV);
111 my $status_fmt = '%12s %12s %s';
112 my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
116 sub is_initial_commit
{
117 $initial = system('git rev-parse HEAD -- >/dev/null 2>&1') != 0
118 unless defined $initial;
124 return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
127 # Returns list of hashes, contents of each of which are:
129 # BINARY: is a binary path
130 # INDEX: is index different from HEAD?
131 # FILE: is file different from index?
132 # INDEX_ADDDEL: is it add/delete between HEAD and index?
133 # FILE_ADDDEL: is it add/delete between index and file?
138 my ($add, $del, $adddel, $file);
144 } run_cmd_pipe
(qw(git ls-files --exclude-standard --), @ARGV);
145 return if (!@tracked);
148 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
149 for (run_cmd_pipe
(qw(git diff-index --cached
150 --numstat --summary), $reference,
152 if (($add, $del, $file) =
153 /^([-\d]+) ([-\d]+) (.*)/) {
155 if ($add eq '-' && $del eq '-') {
160 $change = "+$add/-$del";
168 elsif (($adddel, $file) =
169 /^ (create|delete) mode [0-7]+ (.*)$/) {
170 $data{$file}{INDEX_ADDDEL
} = $adddel;
174 for (run_cmd_pipe
(qw(git diff-files --numstat --summary --), @tracked)) {
175 if (($add, $del, $file) =
176 /^([-\d]+) ([-\d]+) (.*)/) {
177 if (!exists $data{$file}) {
179 INDEX
=> 'unchanged',
184 if ($add eq '-' && $del eq '-') {
189 $change = "+$add/-$del";
191 $data{$file}{FILE
} = $change;
193 $data{$file}{BINARY
} = 1;
196 elsif (($adddel, $file) =
197 /^ (create|delete) mode [0-7]+ (.*)$/) {
198 $data{$file}{FILE_ADDDEL
} = $adddel;
202 for (sort keys %data) {
206 if ($only eq 'index-only') {
207 next if ($it->{INDEX
} eq 'unchanged');
209 if ($only eq 'file-only') {
210 next if ($it->{FILE
} eq 'nothing');
222 my ($string, @stuff) = @_;
224 for (my $i = 0; $i < @stuff; $i++) {
228 if ((ref $it) eq 'ARRAY') {
236 if ($it =~ /^$string/) {
240 if (defined $hit && defined $found) {
250 # inserts string into trie and updates count for each character
252 my ($trie, $string) = @_;
253 foreach (split //, $string) {
254 $trie = $trie->{$_} ||= {COUNT
=> 0};
259 # returns an array of tuples (prefix, remainder)
260 sub find_unique_prefixes
{
264 # any single prefix exceeding the soft limit is omitted
265 # if any prefix exceeds the hard limit all are omitted
266 # 0 indicates no limit
270 # build a trie modelling all possible options
272 foreach my $print (@stuff) {
273 if ((ref $print) eq 'ARRAY') {
274 $print = $print->[0];
276 elsif ((ref $print) eq 'HASH') {
277 $print = $print->{VALUE
};
279 update_trie
(\
%trie, $print);
280 push @return, $print;
283 # use the trie to find the unique prefixes
284 for (my $i = 0; $i < @return; $i++) {
285 my $ret = $return[$i];
286 my @letters = split //, $ret;
288 my ($prefix, $remainder);
290 for ($j = 0; $j < @letters; $j++) {
291 my $letter = $letters[$j];
292 if ($search{$letter}{COUNT
} == 1) {
293 $prefix = substr $ret, 0, $j + 1;
294 $remainder = substr $ret, $j + 1;
298 my $prefix = substr $ret, 0, $j;
300 if ($hard_limit && $j + 1 > $hard_limit);
302 %search = %{$search{$letter}};
304 if ($soft_limit && $j + 1 > $soft_limit) {
308 $return[$i] = [$prefix, $remainder];
313 # filters out prefixes which have special meaning to list_and_choose()
314 sub is_valid_prefix
{
316 return (defined $prefix) &&
317 !($prefix =~ /[\s,]/) && # separators
318 !($prefix =~ /^-/) && # deselection
319 !($prefix =~ /^\d+/) && # selection
320 ($prefix ne '*') && # "all" wildcard
321 ($prefix ne '?'); # prompt help
324 # given a prefix/remainder tuple return a string with the prefix highlighted
325 # for now use square brackets; later might use ANSI colors (underline, bold)
326 sub highlight_prefix
{
328 my $remainder = shift;
330 if (!defined $prefix) {
334 if (!is_valid_prefix
($prefix)) {
335 return "$prefix$remainder";
338 if (!$menu_use_color) {
339 return "[$prefix]$remainder";
342 return "$prompt_color$prefix$normal_color$remainder";
346 print STDERR colored
$error_color, @_;
349 sub list_and_choose
{
350 my ($opts, @stuff) = @_;
351 my (@chosen, @return);
353 my @prefixes = find_unique_prefixes
(@stuff) unless $opts->{LIST_ONLY
};
359 if ($opts->{HEADER
}) {
360 if (!$opts->{LIST_FLAT
}) {
363 print colored
$header_color, "$opts->{HEADER}\n";
365 for ($i = 0; $i < @stuff; $i++) {
366 my $chosen = $chosen[$i] ?
'*' : ' ';
367 my $print = $stuff[$i];
368 my $ref = ref $print;
369 my $highlighted = highlight_prefix
(@
{$prefixes[$i]})
371 if ($ref eq 'ARRAY') {
372 $print = $highlighted || $print->[0];
374 elsif ($ref eq 'HASH') {
375 my $value = $highlighted || $print->{VALUE
};
376 $print = sprintf($status_fmt,
382 $print = $highlighted || $print;
384 printf("%s%2d: %s", $chosen, $i+1, $print);
385 if (($opts->{LIST_FLAT
}) &&
386 (($i + 1) % ($opts->{LIST_FLAT
}))) {
399 return if ($opts->{LIST_ONLY
});
401 print colored
$prompt_color, $opts->{PROMPT
};
402 if ($opts->{SINGLETON
}) {
411 $opts->{ON_EOF
}->() if $opts->{ON_EOF
};
418 singleton_prompt_help_cmd
() :
422 for my $choice (split(/[\s,]+/, $line)) {
426 # Input that begins with '-'; unchoose
427 if ($choice =~ s/^-//) {
430 # A range can be specified like 5-7 or 5-.
431 if ($choice =~ /^(\d+)-(\d*)$/) {
432 ($bottom, $top) = ($1, length($2) ?
$2 : 1 + @stuff);
434 elsif ($choice =~ /^\d+$/) {
435 $bottom = $top = $choice;
437 elsif ($choice eq '*') {
442 $bottom = $top = find_unique
($choice, @stuff);
443 if (!defined $bottom) {
444 error_msg
"Huh ($choice)?\n";
448 if ($opts->{SINGLETON
} && $bottom != $top) {
449 error_msg
"Huh ($choice)?\n";
452 for ($i = $bottom-1; $i <= $top-1; $i++) {
453 next if (@stuff <= $i || $i < 0);
454 $chosen[$i] = $choose;
457 last if ($opts->{IMMEDIATE
} || $line eq '*');
459 for ($i = 0; $i < @stuff; $i++) {
461 push @return, $stuff[$i];
467 sub singleton_prompt_help_cmd
{
468 print colored
$help_color, <<\EOF
;
470 1 - select a numbered item
471 foo
- select item based on unique prefix
472 - (empty
) select nothing
476 sub prompt_help_cmd
{
477 print colored
$help_color, <<\EOF
;
479 1 - select a single item
480 3-5 - select a range of items
481 2-3,6-9 - select multiple ranges
482 foo
- select item based on unique prefix
483 -... - unselect specified items
485 - (empty
) finish selecting
490 list_and_choose
({ LIST_ONLY
=> 1, HEADER
=> $status_head },
500 print "$cnt paths\n";
508 my @mods = list_modified
('file-only');
511 my @update = list_and_choose
({ PROMPT
=> 'Update',
512 HEADER
=> $status_head, },
515 system(qw(git update-index --add --remove --),
516 map { $_->{VALUE
} } @update);
517 say_n_paths
('updated', @update);
523 my @update = list_and_choose
({ PROMPT
=> 'Revert',
524 HEADER
=> $status_head, },
527 if (is_initial_commit
()) {
528 system(qw(git rm --cached),
529 map { $_->{VALUE
} } @update);
532 my @lines = run_cmd_pipe
(qw(git ls-tree HEAD --),
533 map { $_->{VALUE
} } @update);
535 open $fh, '| git update-index --index-info'
542 if ($_->{INDEX_ADDDEL
} &&
543 $_->{INDEX_ADDDEL
} eq 'create') {
544 system(qw(git update-index --force-remove --),
546 print "note: $_->{VALUE} is untracked now.\n";
551 say_n_paths
('reverted', @update);
556 sub add_untracked_cmd
{
557 my @add = list_and_choose
({ PROMPT
=> 'Add untracked' },
560 system(qw(git update-index --add --), @add);
561 say_n_paths
('added', @add);
568 my @diff = run_cmd_pipe
(qw(git diff-files -p --), $path);
570 if ($diff_use_color) {
571 @colored = run_cmd_pipe
(qw(git diff-files -p --color --), $path);
573 my (@hunk) = { TEXT
=> [], DISPLAY
=> [] };
575 for (my $i = 0; $i < @diff; $i++) {
576 if ($diff[$i] =~ /^@@ /) {
577 push @hunk, { TEXT
=> [], DISPLAY
=> [] };
579 push @
{$hunk[-1]{TEXT
}}, $diff[$i];
580 push @
{$hunk[-1]{DISPLAY
}},
581 ($diff_use_color ?
$colored[$i] : $diff[$i]);
586 sub parse_diff_header
{
589 my $head = { TEXT
=> [], DISPLAY
=> [] };
590 my $mode = { TEXT
=> [], DISPLAY
=> [] };
592 for (my $i = 0; $i < @
{$src->{TEXT
}}; $i++) {
593 my $dest = $src->{TEXT
}->[$i] =~ /^(old|new) mode (\d+)$/ ?
595 push @
{$dest->{TEXT
}}, $src->{TEXT
}->[$i];
596 push @
{$dest->{DISPLAY
}}, $src->{DISPLAY
}->[$i];
598 return ($head, $mode);
601 sub hunk_splittable
{
604 my @s = split_hunk
($text);
608 sub parse_hunk_header
{
610 my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
611 $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
612 $o_cnt = 1 unless defined $o_cnt;
613 $n_cnt = 1 unless defined $n_cnt;
614 return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
618 my ($text, $display) = @_;
620 if (!defined $display) {
623 # If there are context lines in the middle of a hunk,
624 # it can be split, but we would need to take care of
627 my ($o_ofs, undef, $n_ofs) = parse_hunk_header
($text->[0]);
632 my $next_hunk_start = undef;
633 my $i = $hunk_start - 1;
646 while (++$i < @
$text) {
647 my $line = $text->[$i];
648 my $display = $display->[$i];
650 if ($this->{ADDDEL
} &&
651 !defined $next_hunk_start) {
652 # We have seen leading context and
653 # adds/dels and then here is another
654 # context, which is trailing for this
655 # split hunk and leading for the next
657 $next_hunk_start = $i;
659 push @
{$this->{TEXT
}}, $line;
660 push @
{$this->{DISPLAY
}}, $display;
663 if (defined $next_hunk_start) {
670 if (defined $next_hunk_start) {
671 # We are done with the current hunk and
672 # this is the first real change for the
674 $hunk_start = $next_hunk_start;
675 $o_ofs = $this->{OLD
} + $this->{OCNT
};
676 $n_ofs = $this->{NEW
} + $this->{NCNT
};
677 $o_ofs -= $this->{POSTCTX
};
678 $n_ofs -= $this->{POSTCTX
};
682 push @
{$this->{TEXT
}}, $line;
683 push @
{$this->{DISPLAY
}}, $display;
697 for my $hunk (@split) {
698 $o_ofs = $hunk->{OLD
};
699 $n_ofs = $hunk->{NEW
};
700 my $o_cnt = $hunk->{OCNT
};
701 my $n_cnt = $hunk->{NCNT
};
703 my $head = ("@@ -$o_ofs" .
704 (($o_cnt != 1) ?
",$o_cnt" : '') .
706 (($n_cnt != 1) ?
",$n_cnt" : '') .
708 my $display_head = $head;
709 unshift @
{$hunk->{TEXT
}}, $head;
710 if ($diff_use_color) {
711 $display_head = colored
($fraginfo_color, $head);
713 unshift @
{$hunk->{DISPLAY
}}, $display_head;
721 colored
((/^@/ ?
$fraginfo_color :
722 /^\+/ ?
$diff_new_color :
723 /^-/ ?
$diff_old_color :
729 sub edit_hunk_manually
{
732 my $hunkfile = $repo->repo_path . "/addp-hunk-edit.diff";
734 open $fh, '>', $hunkfile
735 or die "failed to open hunk edit file for writing: " . $!;
736 print $fh "# Manual hunk edit mode -- see bottom for a quick guide\n";
740 # To remove '-' lines, make them ' ' lines (context).
741 # To remove '+' lines, delete them.
742 # Lines starting with # will be removed.
744 # If the patch applies cleanly, the edited hunk will immediately be
745 # marked for staging. If it does not apply cleanly, you will be given
746 # an opportunity to edit again. If all lines of the hunk are removed,
747 # then the edit is aborted and the hunk is left unchanged.
751 my $editor = $ENV{GIT_EDITOR
} || $repo->config("core.editor")
752 || $ENV{VISUAL
} || $ENV{EDITOR
} || "vi";
753 system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
755 open $fh, '<', $hunkfile
756 or die "failed to open hunk edit file for reading: " . $!;
757 my @newtext = grep { !/^#/ } <$fh>;
761 # Abort if nothing remains
762 if (!grep { /\S/ } @newtext) {
766 # Reinsert the first hunk header if the user accidentally deleted it
767 if ($newtext[0] !~ /^@/) {
768 unshift @newtext, $oldtext->[0];
775 open $fh, '| git apply --recount --cached --check';
777 print $fh @
{$h->{TEXT
}};
782 sub _restore_terminal_and_die
{
788 sub prompt_single_character
{
790 local $SIG{TERM
} = \
&_restore_terminal_and_die
;
791 local $SIG{INT
} = \
&_restore_terminal_and_die
;
795 print "$key" if defined $key;
806 print colored
$prompt_color, $prompt;
807 my $line = prompt_single_character
;
808 return 0 if $line =~ /^n/i;
809 return 1 if $line =~ /^y/i;
814 my ($head, $hunk, $ix) = @_;
815 my $text = $hunk->[$ix]->{TEXT
};
818 $text = edit_hunk_manually
($text);
819 if (!defined $text) {
822 my $newhunk = { TEXT
=> $text, USE
=> 1 };
823 if (diff_applies
($head,
826 @
{$hunk}[$ix+1..$#{$hunk}])) {
827 $newhunk->{DISPLAY
} = [color_diff
(@
{$text})];
832 'Your edited hunk does not apply. Edit again '
833 . '(saying "no" discards!) [y/n]? '
840 print colored
$help_color, <<\EOF
;
842 n
- do not stage this hunk
843 a
- stage this
and all the remaining hunks
in the file
844 d
- do not stage this hunk nor any of the remaining hunks
in the file
845 g
- select a hunk to go to
846 / - search
for a hunk matching the
given regex
847 j
- leave this hunk undecided
, see
next undecided hunk
848 J
- leave this hunk undecided
, see
next hunk
849 k
- leave this hunk undecided
, see previous undecided hunk
850 K
- leave this hunk undecided
, see previous hunk
851 s
- split the current hunk into smaller hunks
852 e
- manually edit the current hunk
857 sub patch_update_cmd
{
858 my @all_mods = list_modified
('file-only');
859 my @mods = grep { !($_->{BINARY
}) } @all_mods;
864 print STDERR
"Only binary files changed.\n";
866 print STDERR
"No changes.\n";
874 @them = list_and_choose
({ PROMPT
=> 'Patch update',
875 HEADER
=> $status_head, },
879 patch_update_file
($_->{VALUE
});
883 # Generate a one line summary of a hunk.
886 my $summary = $rhunk->{TEXT
}[0];
888 # Keep the line numbers, discard extra context.
889 $summary =~ s/@@(.*?)@@.*/$1 /s;
890 $summary .= " " x
(20 - length $summary);
892 # Add some user context.
893 for my $line (@
{$rhunk->{TEXT
}}) {
894 if ($line =~ m/^[+-].*\w/) {
901 return substr($summary, 0, 80) . "\n";
905 # Print a one-line summary of each hunk in the array ref in
906 # the first argument, starting wih the index in the 2nd.
908 my ($hunks, $i) = @_;
911 for (; $i < @
$hunks && $ctr < 20; $i++, $ctr++) {
913 if (defined $hunks->[$i]{USE
}) {
914 $status = $hunks->[$i]{USE
} ?
"+" : "-";
919 summarize_hunk
($hunks->[$i]);
924 sub patch_update_file
{
927 my ($head, @hunk) = parse_diff
($path);
928 ($head, my $mode) = parse_diff_header
($head);
929 for (@
{$head->{DISPLAY
}}) {
933 if (@
{$mode->{TEXT
}}) {
935 print @
{$mode->{DISPLAY
}};
936 print colored
$prompt_color,
937 "Stage mode change [y/n/a/d/?]? ";
938 my $line = prompt_single_character
;
939 if ($line =~ /^y/i) {
943 elsif ($line =~ /^n/i) {
947 elsif ($line =~ /^a/i) {
948 $_->{USE
} = 1 foreach ($mode, @hunk);
951 elsif ($line =~ /^d/i) {
952 $_->{USE
} = 0 foreach ($mode, @hunk);
966 my ($prev, $next, $other, $undecided, $i);
972 for ($i = 0; $i < $ix; $i++) {
973 if (!defined $hunk[$i]{USE
}) {
982 for ($i = $ix + 1; $i < $num; $i++) {
983 if (!defined $hunk[$i]{USE
}) {
989 if ($ix < $num - 1) {
995 for ($i = 0; $i < $num; $i++) {
996 if (!defined $hunk[$i]{USE
}) {
1001 last if (!$undecided);
1003 if (hunk_splittable
($hunk[$ix]{TEXT
})) {
1007 for (@
{$hunk[$ix]{DISPLAY
}}) {
1010 print colored
$prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
1011 my $line = prompt_single_character
;
1013 if ($line =~ /^y/i) {
1014 $hunk[$ix]{USE
} = 1;
1016 elsif ($line =~ /^n/i) {
1017 $hunk[$ix]{USE
} = 0;
1019 elsif ($line =~ /^a/i) {
1020 while ($ix < $num) {
1021 if (!defined $hunk[$ix]{USE
}) {
1022 $hunk[$ix]{USE
} = 1;
1028 elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1030 my $no = $ix > 10 ?
$ix - 10 : 0;
1031 while ($response eq '') {
1033 $no = display_hunks
(\
@hunk, $no);
1035 $extra = " (<ret> to see more)";
1037 print "go to which hunk$extra? ";
1038 $response = <STDIN
>;
1039 if (!defined $response) {
1044 if ($response !~ /^\s*\d+\s*$/) {
1045 error_msg
"Invalid number: '$response'\n";
1046 } elsif (0 < $response && $response <= $num) {
1047 $ix = $response - 1;
1049 error_msg
"Sorry, only $num hunks available.\n";
1053 elsif ($line =~ /^d/i) {
1054 while ($ix < $num) {
1055 if (!defined $hunk[$ix]{USE
}) {
1056 $hunk[$ix]{USE
} = 0;
1062 elsif ($line =~ m
|^/(.*)|) {
1065 print colored
$prompt_color, "search for regex? ";
1067 if (defined $regex) {
1073 $search_string = qr{$regex}m;
1076 my ($err,$exp) = ($@
, $1);
1077 $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1078 error_msg
"Malformed search regexp $exp: $err\n";
1083 my $text = join ("", @
{$hunk[$iy]{TEXT
}});
1084 last if ($text =~ $search_string);
1086 $iy = 0 if ($iy >= $num);
1088 error_msg
"No hunk matches the given pattern\n";
1095 elsif ($line =~ /^K/) {
1096 if ($other =~ /K/) {
1100 error_msg
"No previous hunk\n";
1104 elsif ($line =~ /^J/) {
1105 if ($other =~ /J/) {
1109 error_msg
"No next hunk\n";
1113 elsif ($line =~ /^k/) {
1114 if ($other =~ /k/) {
1118 !defined $hunk[$ix]{USE
});
1122 error_msg
"No previous hunk\n";
1126 elsif ($line =~ /^j/) {
1127 if ($other !~ /j/) {
1128 error_msg
"No next hunk\n";
1132 elsif ($other =~ /s/ && $line =~ /^s/) {
1133 my @split = split_hunk
($hunk[$ix]{TEXT
}, $hunk[$ix]{DISPLAY
});
1135 print colored
$header_color, "Split into ",
1136 scalar(@split), " hunks.\n";
1138 splice (@hunk, $ix, 1, @split);
1139 $num = scalar @hunk;
1142 elsif ($line =~ /^e/) {
1143 my $newhunk = edit_hunk_loop
($head, \
@hunk, $ix);
1144 if (defined $newhunk) {
1145 splice @hunk, $ix, 1, $newhunk;
1149 help_patch_cmd
($other);
1155 last if ($ix >= $num ||
1156 !defined $hunk[$ix]{USE
});
1164 push @result, @
{$mode->{TEXT
}};
1168 push @result, @
{$_->{TEXT
}};
1175 open $fh, '| git apply --cached --recount';
1176 for (@
{$head->{TEXT
}}, @result) {
1180 for (@
{$head->{TEXT
}}, @result) {
1191 my @mods = list_modified
('index-only');
1192 @mods = grep { !($_->{BINARY
}) } @mods;
1194 my (@them) = list_and_choose
({ PROMPT
=> 'Review diff',
1196 HEADER
=> $status_head, },
1199 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
1200 system(qw(git diff -p --cached), $reference, '--',
1201 map { $_->{VALUE
} } @them);
1210 print colored
$help_color, <<\EOF
;
1211 status
- show paths with changes
1212 update
- add working tree
state to the staged set of changes
1213 revert
- revert staged set of changes back to the HEAD version
1214 patch
- pick hunks
and update selectively
1215 diff
- view diff between HEAD
and index
1216 add untracked
- add contents of untracked files to the staged set of changes
1221 return unless @ARGV;
1222 my $arg = shift @ARGV;
1223 if ($arg eq "--patch") {
1225 $arg = shift @ARGV or die "missing --";
1226 die "invalid argument $arg, expecting --"
1227 unless $arg eq "--";
1229 elsif ($arg ne "--") {
1230 die "invalid argument $arg, expecting --";
1235 my @cmd = ([ 'status', \
&status_cmd
, ],
1236 [ 'update', \
&update_cmd
, ],
1237 [ 'revert', \
&revert_cmd
, ],
1238 [ 'add untracked', \
&add_untracked_cmd
, ],
1239 [ 'patch', \
&patch_update_cmd
, ],
1240 [ 'diff', \
&diff_cmd
, ],
1241 [ 'quit', \
&quit_cmd
, ],
1242 [ 'help', \
&help_cmd
, ],
1245 my ($it) = list_and_choose
({ PROMPT
=> 'What now',
1248 HEADER
=> '*** Commands ***',
1249 ON_EOF
=> \
&quit_cmd
,
1250 IMMEDIATE
=> 1 }, @cmd);