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') or
19 $error_color = $repo->get_color('color.interactive.error',
23 my $diff_use_color = $repo->get_colorbool('color.diff');
24 my ($fraginfo_color) =
26 $repo->get_color('color.diff.frag', 'cyan'),
28 my ($diff_plain_color) =
30 $repo->get_color('color.diff.plain', ''),
32 my ($diff_old_color) =
34 $repo->get_color('color.diff.old', 'red'),
36 my ($diff_new_color) =
38 $repo->get_color('color.diff.new', 'green'),
41 my $normal_color = $repo->get_color("", "reset");
46 if ($repo->config_bool("interactive.singlekey")) {
48 require Term
::ReadKey
;
49 Term
::ReadKey
->import;
56 my $string = join("", @_);
59 # Put a color code at the beginning of each line, a reset at the end
60 # color after newlines that are not at the end of the string
61 $string =~ s/(\n+)(.)/$1$color$2/g;
62 # reset before newlines
63 $string =~ s/(\n+)/$normal_color$1/g;
64 # codes at beginning and end (if necessary):
65 $string =~ s/^/$color/;
66 $string =~ s/$/$normal_color/ unless $string =~ /\n$/;
71 # command line options
75 if ($^O
eq 'MSWin32' || $^O
eq 'msys') {
76 my @invalid = grep {m/[":*]/} @_;
77 die "$^O does not support: @invalid\n" if @invalid;
78 my @args = map { m/ /o ?
"\"$_\"": $_ } @_;
82 open($fh, '-|', @_) or die;
87 my ($GIT_DIR) = run_cmd_pipe
(qw(git rev-parse --git-dir));
89 if (!defined $GIT_DIR) {
90 exit(1); # rev-parse would have already said "not a git repo"
96 open $fh, 'git update-index --refresh |'
99 ;# ignore 'needs update'
109 run_cmd_pipe
(qw(git ls-files --others --exclude-standard --), @ARGV);
112 my $status_fmt = '%12s %12s %s';
113 my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
117 sub is_initial_commit
{
118 $initial = system('git rev-parse HEAD -- >/dev/null 2>&1') != 0
119 unless defined $initial;
125 return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
128 # Returns list of hashes, contents of each of which are:
130 # BINARY: is a binary path
131 # INDEX: is index different from HEAD?
132 # FILE: is file different from index?
133 # INDEX_ADDDEL: is it add/delete between HEAD and index?
134 # FILE_ADDDEL: is it add/delete between index and file?
139 my ($add, $del, $adddel, $file);
145 } run_cmd_pipe
(qw(git ls-files --exclude-standard --), @ARGV);
146 return if (!@tracked);
149 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
150 for (run_cmd_pipe
(qw(git diff-index --cached
151 --numstat --summary), $reference,
153 if (($add, $del, $file) =
154 /^([-\d]+) ([-\d]+) (.*)/) {
156 if ($add eq '-' && $del eq '-') {
161 $change = "+$add/-$del";
169 elsif (($adddel, $file) =
170 /^ (create|delete) mode [0-7]+ (.*)$/) {
171 $data{$file}{INDEX_ADDDEL
} = $adddel;
175 for (run_cmd_pipe
(qw(git diff-files --numstat --summary --), @tracked)) {
176 if (($add, $del, $file) =
177 /^([-\d]+) ([-\d]+) (.*)/) {
178 if (!exists $data{$file}) {
180 INDEX
=> 'unchanged',
185 if ($add eq '-' && $del eq '-') {
190 $change = "+$add/-$del";
192 $data{$file}{FILE
} = $change;
194 $data{$file}{BINARY
} = 1;
197 elsif (($adddel, $file) =
198 /^ (create|delete) mode [0-7]+ (.*)$/) {
199 $data{$file}{FILE_ADDDEL
} = $adddel;
203 for (sort keys %data) {
207 if ($only eq 'index-only') {
208 next if ($it->{INDEX
} eq 'unchanged');
210 if ($only eq 'file-only') {
211 next if ($it->{FILE
} eq 'nothing');
223 my ($string, @stuff) = @_;
225 for (my $i = 0; $i < @stuff; $i++) {
229 if ((ref $it) eq 'ARRAY') {
237 if ($it =~ /^$string/) {
241 if (defined $hit && defined $found) {
251 # inserts string into trie and updates count for each character
253 my ($trie, $string) = @_;
254 foreach (split //, $string) {
255 $trie = $trie->{$_} ||= {COUNT
=> 0};
260 # returns an array of tuples (prefix, remainder)
261 sub find_unique_prefixes
{
265 # any single prefix exceeding the soft limit is omitted
266 # if any prefix exceeds the hard limit all are omitted
267 # 0 indicates no limit
271 # build a trie modelling all possible options
273 foreach my $print (@stuff) {
274 if ((ref $print) eq 'ARRAY') {
275 $print = $print->[0];
277 elsif ((ref $print) eq 'HASH') {
278 $print = $print->{VALUE
};
280 update_trie
(\
%trie, $print);
281 push @return, $print;
284 # use the trie to find the unique prefixes
285 for (my $i = 0; $i < @return; $i++) {
286 my $ret = $return[$i];
287 my @letters = split //, $ret;
289 my ($prefix, $remainder);
291 for ($j = 0; $j < @letters; $j++) {
292 my $letter = $letters[$j];
293 if ($search{$letter}{COUNT
} == 1) {
294 $prefix = substr $ret, 0, $j + 1;
295 $remainder = substr $ret, $j + 1;
299 my $prefix = substr $ret, 0, $j;
301 if ($hard_limit && $j + 1 > $hard_limit);
303 %search = %{$search{$letter}};
305 if ($soft_limit && $j + 1 > $soft_limit) {
309 $return[$i] = [$prefix, $remainder];
314 # filters out prefixes which have special meaning to list_and_choose()
315 sub is_valid_prefix
{
317 return (defined $prefix) &&
318 !($prefix =~ /[\s,]/) && # separators
319 !($prefix =~ /^-/) && # deselection
320 !($prefix =~ /^\d+/) && # selection
321 ($prefix ne '*') && # "all" wildcard
322 ($prefix ne '?'); # prompt help
325 # given a prefix/remainder tuple return a string with the prefix highlighted
326 # for now use square brackets; later might use ANSI colors (underline, bold)
327 sub highlight_prefix
{
329 my $remainder = shift;
331 if (!defined $prefix) {
335 if (!is_valid_prefix
($prefix)) {
336 return "$prefix$remainder";
339 if (!$menu_use_color) {
340 return "[$prefix]$remainder";
343 return "$prompt_color$prefix$normal_color$remainder";
347 print STDERR colored
$error_color, @_;
350 sub list_and_choose
{
351 my ($opts, @stuff) = @_;
352 my (@chosen, @return);
354 my @prefixes = find_unique_prefixes
(@stuff) unless $opts->{LIST_ONLY
};
360 if ($opts->{HEADER
}) {
361 if (!$opts->{LIST_FLAT
}) {
364 print colored
$header_color, "$opts->{HEADER}\n";
366 for ($i = 0; $i < @stuff; $i++) {
367 my $chosen = $chosen[$i] ?
'*' : ' ';
368 my $print = $stuff[$i];
369 my $ref = ref $print;
370 my $highlighted = highlight_prefix
(@
{$prefixes[$i]})
372 if ($ref eq 'ARRAY') {
373 $print = $highlighted || $print->[0];
375 elsif ($ref eq 'HASH') {
376 my $value = $highlighted || $print->{VALUE
};
377 $print = sprintf($status_fmt,
383 $print = $highlighted || $print;
385 printf("%s%2d: %s", $chosen, $i+1, $print);
386 if (($opts->{LIST_FLAT
}) &&
387 (($i + 1) % ($opts->{LIST_FLAT
}))) {
400 return if ($opts->{LIST_ONLY
});
402 print colored
$prompt_color, $opts->{PROMPT
};
403 if ($opts->{SINGLETON
}) {
412 $opts->{ON_EOF
}->() if $opts->{ON_EOF
};
419 singleton_prompt_help_cmd
() :
423 for my $choice (split(/[\s,]+/, $line)) {
427 # Input that begins with '-'; unchoose
428 if ($choice =~ s/^-//) {
431 # A range can be specified like 5-7 or 5-.
432 if ($choice =~ /^(\d+)-(\d*)$/) {
433 ($bottom, $top) = ($1, length($2) ?
$2 : 1 + @stuff);
435 elsif ($choice =~ /^\d+$/) {
436 $bottom = $top = $choice;
438 elsif ($choice eq '*') {
443 $bottom = $top = find_unique
($choice, @stuff);
444 if (!defined $bottom) {
445 error_msg
"Huh ($choice)?\n";
449 if ($opts->{SINGLETON
} && $bottom != $top) {
450 error_msg
"Huh ($choice)?\n";
453 for ($i = $bottom-1; $i <= $top-1; $i++) {
454 next if (@stuff <= $i || $i < 0);
455 $chosen[$i] = $choose;
458 last if ($opts->{IMMEDIATE
} || $line eq '*');
460 for ($i = 0; $i < @stuff; $i++) {
462 push @return, $stuff[$i];
468 sub singleton_prompt_help_cmd
{
469 print colored
$help_color, <<\EOF
;
471 1 - select a numbered item
472 foo
- select item based on unique prefix
473 - (empty
) select nothing
477 sub prompt_help_cmd
{
478 print colored
$help_color, <<\EOF
;
480 1 - select a single item
481 3-5 - select a range of items
482 2-3,6-9 - select multiple ranges
483 foo
- select item based on unique prefix
484 -... - unselect specified items
486 - (empty
) finish selecting
491 list_and_choose
({ LIST_ONLY
=> 1, HEADER
=> $status_head },
501 print "$cnt paths\n";
509 my @mods = list_modified
('file-only');
512 my @update = list_and_choose
({ PROMPT
=> 'Update',
513 HEADER
=> $status_head, },
516 system(qw(git update-index --add --remove --),
517 map { $_->{VALUE
} } @update);
518 say_n_paths
('updated', @update);
524 my @update = list_and_choose
({ PROMPT
=> 'Revert',
525 HEADER
=> $status_head, },
528 if (is_initial_commit
()) {
529 system(qw(git rm --cached),
530 map { $_->{VALUE
} } @update);
533 my @lines = run_cmd_pipe
(qw(git ls-tree HEAD --),
534 map { $_->{VALUE
} } @update);
536 open $fh, '| git update-index --index-info'
543 if ($_->{INDEX_ADDDEL
} &&
544 $_->{INDEX_ADDDEL
} eq 'create') {
545 system(qw(git update-index --force-remove --),
547 print "note: $_->{VALUE} is untracked now.\n";
552 say_n_paths
('reverted', @update);
557 sub add_untracked_cmd
{
558 my @add = list_and_choose
({ PROMPT
=> 'Add untracked' },
561 system(qw(git update-index --add --), @add);
562 say_n_paths
('added', @add);
569 my @diff = run_cmd_pipe
(qw(git diff-files -p --), $path);
571 if ($diff_use_color) {
572 @colored = run_cmd_pipe
(qw(git diff-files -p --color --), $path);
574 my (@hunk) = { TEXT
=> [], DISPLAY
=> [] };
576 for (my $i = 0; $i < @diff; $i++) {
577 if ($diff[$i] =~ /^@@ /) {
578 push @hunk, { TEXT
=> [], DISPLAY
=> [] };
580 push @
{$hunk[-1]{TEXT
}}, $diff[$i];
581 push @
{$hunk[-1]{DISPLAY
}},
582 ($diff_use_color ?
$colored[$i] : $diff[$i]);
587 sub parse_diff_header
{
590 my $head = { TEXT
=> [], DISPLAY
=> [] };
591 my $mode = { TEXT
=> [], DISPLAY
=> [] };
593 for (my $i = 0; $i < @
{$src->{TEXT
}}; $i++) {
594 my $dest = $src->{TEXT
}->[$i] =~ /^(old|new) mode (\d+)$/ ?
596 push @
{$dest->{TEXT
}}, $src->{TEXT
}->[$i];
597 push @
{$dest->{DISPLAY
}}, $src->{DISPLAY
}->[$i];
599 return ($head, $mode);
602 sub hunk_splittable
{
605 my @s = split_hunk
($text);
609 sub parse_hunk_header
{
611 my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
612 $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
613 $o_cnt = 1 unless defined $o_cnt;
614 $n_cnt = 1 unless defined $n_cnt;
615 return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
619 my ($text, $display) = @_;
621 if (!defined $display) {
624 # If there are context lines in the middle of a hunk,
625 # it can be split, but we would need to take care of
628 my ($o_ofs, undef, $n_ofs) = parse_hunk_header
($text->[0]);
633 my $next_hunk_start = undef;
634 my $i = $hunk_start - 1;
647 while (++$i < @
$text) {
648 my $line = $text->[$i];
649 my $display = $display->[$i];
651 if ($this->{ADDDEL
} &&
652 !defined $next_hunk_start) {
653 # We have seen leading context and
654 # adds/dels and then here is another
655 # context, which is trailing for this
656 # split hunk and leading for the next
658 $next_hunk_start = $i;
660 push @
{$this->{TEXT
}}, $line;
661 push @
{$this->{DISPLAY
}}, $display;
664 if (defined $next_hunk_start) {
671 if (defined $next_hunk_start) {
672 # We are done with the current hunk and
673 # this is the first real change for the
675 $hunk_start = $next_hunk_start;
676 $o_ofs = $this->{OLD
} + $this->{OCNT
};
677 $n_ofs = $this->{NEW
} + $this->{NCNT
};
678 $o_ofs -= $this->{POSTCTX
};
679 $n_ofs -= $this->{POSTCTX
};
683 push @
{$this->{TEXT
}}, $line;
684 push @
{$this->{DISPLAY
}}, $display;
698 for my $hunk (@split) {
699 $o_ofs = $hunk->{OLD
};
700 $n_ofs = $hunk->{NEW
};
701 my $o_cnt = $hunk->{OCNT
};
702 my $n_cnt = $hunk->{NCNT
};
704 my $head = ("@@ -$o_ofs" .
705 (($o_cnt != 1) ?
",$o_cnt" : '') .
707 (($n_cnt != 1) ?
",$n_cnt" : '') .
709 my $display_head = $head;
710 unshift @
{$hunk->{TEXT
}}, $head;
711 if ($diff_use_color) {
712 $display_head = colored
($fraginfo_color, $head);
714 unshift @
{$hunk->{DISPLAY
}}, $display_head;
722 colored
((/^@/ ?
$fraginfo_color :
723 /^\+/ ?
$diff_new_color :
724 /^-/ ?
$diff_old_color :
730 sub edit_hunk_manually
{
733 my $hunkfile = $repo->repo_path . "/addp-hunk-edit.diff";
735 open $fh, '>', $hunkfile
736 or die "failed to open hunk edit file for writing: " . $!;
737 print $fh "# Manual hunk edit mode -- see bottom for a quick guide\n";
741 # To remove '-' lines, make them ' ' lines (context).
742 # To remove '+' lines, delete them.
743 # Lines starting with # will be removed.
745 # If the patch applies cleanly, the edited hunk will immediately be
746 # marked for staging. If it does not apply cleanly, you will be given
747 # an opportunity to edit again. If all lines of the hunk are removed,
748 # then the edit is aborted and the hunk is left unchanged.
752 my $editor = $ENV{GIT_EDITOR
} || $repo->config("core.editor")
753 || $ENV{VISUAL
} || $ENV{EDITOR
} || "vi";
754 system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
756 open $fh, '<', $hunkfile
757 or die "failed to open hunk edit file for reading: " . $!;
758 my @newtext = grep { !/^#/ } <$fh>;
762 # Abort if nothing remains
763 if (!grep { /\S/ } @newtext) {
767 # Reinsert the first hunk header if the user accidentally deleted it
768 if ($newtext[0] !~ /^@/) {
769 unshift @newtext, $oldtext->[0];
776 open $fh, '| git apply --recount --cached --check';
778 print $fh @
{$h->{TEXT
}};
783 sub _restore_terminal_and_die
{
789 sub prompt_single_character
{
791 local $SIG{TERM
} = \
&_restore_terminal_and_die
;
792 local $SIG{INT
} = \
&_restore_terminal_and_die
;
796 print "$key" if defined $key;
807 print colored
$prompt_color, $prompt;
808 my $line = prompt_single_character
;
809 return 0 if $line =~ /^n/i;
810 return 1 if $line =~ /^y/i;
815 my ($head, $hunk, $ix) = @_;
816 my $text = $hunk->[$ix]->{TEXT
};
819 $text = edit_hunk_manually
($text);
820 if (!defined $text) {
823 my $newhunk = { TEXT
=> $text, USE
=> 1 };
824 if (diff_applies
($head,
827 @
{$hunk}[$ix+1..$#{$hunk}])) {
828 $newhunk->{DISPLAY
} = [color_diff
(@
{$text})];
833 'Your edited hunk does not apply. Edit again '
834 . '(saying "no" discards!) [y/n]? '
841 print colored
$help_color, <<\EOF
;
843 n
- do not stage this hunk
844 a
- stage this
and all the remaining hunks
in the file
845 d
- do not stage this hunk nor any of the remaining hunks
in the file
846 g
- select a hunk to go to
847 / - search
for a hunk matching the
given regex
848 j
- leave this hunk undecided
, see
next undecided hunk
849 J
- leave this hunk undecided
, see
next hunk
850 k
- leave this hunk undecided
, see previous undecided hunk
851 K
- leave this hunk undecided
, see previous hunk
852 s
- split the current hunk into smaller hunks
853 e
- manually edit the current hunk
858 sub patch_update_cmd
{
859 my @all_mods = list_modified
('file-only');
860 my @mods = grep { !($_->{BINARY
}) } @all_mods;
865 print STDERR
"Only binary files changed.\n";
867 print STDERR
"No changes.\n";
875 @them = list_and_choose
({ PROMPT
=> 'Patch update',
876 HEADER
=> $status_head, },
880 patch_update_file
($_->{VALUE
});
884 # Generate a one line summary of a hunk.
887 my $summary = $rhunk->{TEXT
}[0];
889 # Keep the line numbers, discard extra context.
890 $summary =~ s/@@(.*?)@@.*/$1 /s;
891 $summary .= " " x
(20 - length $summary);
893 # Add some user context.
894 for my $line (@
{$rhunk->{TEXT
}}) {
895 if ($line =~ m/^[+-].*\w/) {
902 return substr($summary, 0, 80) . "\n";
906 # Print a one-line summary of each hunk in the array ref in
907 # the first argument, starting wih the index in the 2nd.
909 my ($hunks, $i) = @_;
912 for (; $i < @
$hunks && $ctr < 20; $i++, $ctr++) {
914 if (defined $hunks->[$i]{USE
}) {
915 $status = $hunks->[$i]{USE
} ?
"+" : "-";
920 summarize_hunk
($hunks->[$i]);
925 sub patch_update_file
{
928 my ($head, @hunk) = parse_diff
($path);
929 ($head, my $mode) = parse_diff_header
($head);
930 for (@
{$head->{DISPLAY
}}) {
934 if (@
{$mode->{TEXT
}}) {
936 print @
{$mode->{DISPLAY
}};
937 print colored
$prompt_color,
938 "Stage mode change [y/n/a/d/?]? ";
939 my $line = prompt_single_character
;
940 if ($line =~ /^y/i) {
944 elsif ($line =~ /^n/i) {
948 elsif ($line =~ /^a/i) {
949 $_->{USE
} = 1 foreach ($mode, @hunk);
952 elsif ($line =~ /^d/i) {
953 $_->{USE
} = 0 foreach ($mode, @hunk);
967 my ($prev, $next, $other, $undecided, $i);
973 for ($i = 0; $i < $ix; $i++) {
974 if (!defined $hunk[$i]{USE
}) {
983 for ($i = $ix + 1; $i < $num; $i++) {
984 if (!defined $hunk[$i]{USE
}) {
990 if ($ix < $num - 1) {
996 for ($i = 0; $i < $num; $i++) {
997 if (!defined $hunk[$i]{USE
}) {
1002 last if (!$undecided);
1004 if (hunk_splittable
($hunk[$ix]{TEXT
})) {
1008 for (@
{$hunk[$ix]{DISPLAY
}}) {
1011 print colored
$prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
1012 my $line = prompt_single_character
;
1014 if ($line =~ /^y/i) {
1015 $hunk[$ix]{USE
} = 1;
1017 elsif ($line =~ /^n/i) {
1018 $hunk[$ix]{USE
} = 0;
1020 elsif ($line =~ /^a/i) {
1021 while ($ix < $num) {
1022 if (!defined $hunk[$ix]{USE
}) {
1023 $hunk[$ix]{USE
} = 1;
1029 elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1031 my $no = $ix > 10 ?
$ix - 10 : 0;
1032 while ($response eq '') {
1034 $no = display_hunks
(\
@hunk, $no);
1036 $extra = " (<ret> to see more)";
1038 print "go to which hunk$extra? ";
1039 $response = <STDIN
>;
1040 if (!defined $response) {
1045 if ($response !~ /^\s*\d+\s*$/) {
1046 error_msg
"Invalid number: '$response'\n";
1047 } elsif (0 < $response && $response <= $num) {
1048 $ix = $response - 1;
1050 error_msg
"Sorry, only $num hunks available.\n";
1054 elsif ($line =~ /^d/i) {
1055 while ($ix < $num) {
1056 if (!defined $hunk[$ix]{USE
}) {
1057 $hunk[$ix]{USE
} = 0;
1063 elsif ($line =~ m
|^/(.*)|) {
1066 print colored
$prompt_color, "search for regex? ";
1068 if (defined $regex) {
1074 $search_string = qr{$regex}m;
1077 my ($err,$exp) = ($@
, $1);
1078 $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1079 error_msg
"Malformed search regexp $exp: $err\n";
1084 my $text = join ("", @
{$hunk[$iy]{TEXT
}});
1085 last if ($text =~ $search_string);
1087 $iy = 0 if ($iy >= $num);
1089 error_msg
"No hunk matches the given pattern\n";
1096 elsif ($line =~ /^K/) {
1097 if ($other =~ /K/) {
1101 error_msg
"No previous hunk\n";
1105 elsif ($line =~ /^J/) {
1106 if ($other =~ /J/) {
1110 error_msg
"No next hunk\n";
1114 elsif ($line =~ /^k/) {
1115 if ($other =~ /k/) {
1119 !defined $hunk[$ix]{USE
});
1123 error_msg
"No previous hunk\n";
1127 elsif ($line =~ /^j/) {
1128 if ($other !~ /j/) {
1129 error_msg
"No next hunk\n";
1133 elsif ($other =~ /s/ && $line =~ /^s/) {
1134 my @split = split_hunk
($hunk[$ix]{TEXT
}, $hunk[$ix]{DISPLAY
});
1136 print colored
$header_color, "Split into ",
1137 scalar(@split), " hunks.\n";
1139 splice (@hunk, $ix, 1, @split);
1140 $num = scalar @hunk;
1143 elsif ($line =~ /^e/) {
1144 my $newhunk = edit_hunk_loop
($head, \
@hunk, $ix);
1145 if (defined $newhunk) {
1146 splice @hunk, $ix, 1, $newhunk;
1150 help_patch_cmd
($other);
1156 last if ($ix >= $num ||
1157 !defined $hunk[$ix]{USE
});
1165 push @result, @
{$mode->{TEXT
}};
1169 push @result, @
{$_->{TEXT
}};
1176 open $fh, '| git apply --cached --recount';
1177 for (@
{$head->{TEXT
}}, @result) {
1181 for (@
{$head->{TEXT
}}, @result) {
1192 my @mods = list_modified
('index-only');
1193 @mods = grep { !($_->{BINARY
}) } @mods;
1195 my (@them) = list_and_choose
({ PROMPT
=> 'Review diff',
1197 HEADER
=> $status_head, },
1200 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
1201 system(qw(git diff -p --cached), $reference, '--',
1202 map { $_->{VALUE
} } @them);
1211 print colored
$help_color, <<\EOF
;
1212 status
- show paths with changes
1213 update
- add working tree
state to the staged set of changes
1214 revert
- revert staged set of changes back to the HEAD version
1215 patch
- pick hunks
and update selectively
1216 diff
- view diff between HEAD
and index
1217 add untracked
- add contents of untracked files to the staged set of changes
1222 return unless @ARGV;
1223 my $arg = shift @ARGV;
1224 if ($arg eq "--patch") {
1226 $arg = shift @ARGV or die "missing --";
1227 die "invalid argument $arg, expecting --"
1228 unless $arg eq "--";
1230 elsif ($arg ne "--") {
1231 die "invalid argument $arg, expecting --";
1236 my @cmd = ([ 'status', \
&status_cmd
, ],
1237 [ 'update', \
&update_cmd
, ],
1238 [ 'revert', \
&revert_cmd
, ],
1239 [ 'add untracked', \
&add_untracked_cmd
, ],
1240 [ 'patch', \
&patch_update_cmd
, ],
1241 [ 'diff', \
&diff_cmd
, ],
1242 [ 'quit', \
&quit_cmd
, ],
1243 [ 'help', \
&help_cmd
, ],
1246 my ($it) = list_and_choose
({ PROMPT
=> 'What now',
1249 HEADER
=> '*** Commands ***',
1250 ON_EOF
=> \
&quit_cmd
,
1251 IMMEDIATE
=> 1 }, @cmd);