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 my $diff_use_color = $repo->get_colorbool('color.diff');
17 my ($fraginfo_color) =
19 $repo->get_color('color.diff.frag', 'cyan'),
21 my ($diff_plain_color) =
23 $repo->get_color('color.diff.plain', ''),
25 my ($diff_old_color) =
27 $repo->get_color('color.diff.old', 'red'),
29 my ($diff_new_color) =
31 $repo->get_color('color.diff.new', 'green'),
34 my $normal_color = $repo->get_color("", "reset");
37 if ($repo->config_bool("interactive.singlekey")) {
46 my $string = join("", @_);
49 # Put a color code at the beginning of each line, a reset at the end
50 # color after newlines that are not at the end of the string
51 $string =~ s/(\n+)(.)/$1$color$2/g;
52 # reset before newlines
53 $string =~ s/(\n+)/$normal_color$1/g;
54 # codes at beginning and end (if necessary):
55 $string =~ s/^/$color/;
56 $string =~ s/$/$normal_color/ unless $string =~ /\n$/;
61 # command line options
65 if ($^O
eq 'MSWin32' || $^O
eq 'msys') {
66 my @invalid = grep {m/[":*]/} @_;
67 die "$^O does not support: @invalid\n" if @invalid;
68 my @args = map { m/ /o ?
"\"$_\"": $_ } @_;
72 open($fh, '-|', @_) or die;
77 my ($GIT_DIR) = run_cmd_pipe
(qw(git rev-parse --git-dir));
79 if (!defined $GIT_DIR) {
80 exit(1); # rev-parse would have already said "not a git repo"
86 open $fh, 'git update-index --refresh |'
89 ;# ignore 'needs update'
99 run_cmd_pipe
(qw(git ls-files --others --exclude-standard --), @ARGV);
102 my $status_fmt = '%12s %12s %s';
103 my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
107 sub is_initial_commit
{
108 $initial = system('git rev-parse HEAD -- >/dev/null 2>&1') != 0
109 unless defined $initial;
115 return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
118 # Returns list of hashes, contents of each of which are:
120 # BINARY: is a binary path
121 # INDEX: is index different from HEAD?
122 # FILE: is file different from index?
123 # INDEX_ADDDEL: is it add/delete between HEAD and index?
124 # FILE_ADDDEL: is it add/delete between index and file?
129 my ($add, $del, $adddel, $file);
135 } run_cmd_pipe
(qw(git ls-files --exclude-standard --), @ARGV);
136 return if (!@tracked);
139 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
140 for (run_cmd_pipe
(qw(git diff-index --cached
141 --numstat --summary), $reference,
143 if (($add, $del, $file) =
144 /^([-\d]+) ([-\d]+) (.*)/) {
146 if ($add eq '-' && $del eq '-') {
151 $change = "+$add/-$del";
159 elsif (($adddel, $file) =
160 /^ (create|delete) mode [0-7]+ (.*)$/) {
161 $data{$file}{INDEX_ADDDEL
} = $adddel;
165 for (run_cmd_pipe
(qw(git diff-files --numstat --summary --), @tracked)) {
166 if (($add, $del, $file) =
167 /^([-\d]+) ([-\d]+) (.*)/) {
168 if (!exists $data{$file}) {
170 INDEX
=> 'unchanged',
175 if ($add eq '-' && $del eq '-') {
180 $change = "+$add/-$del";
182 $data{$file}{FILE
} = $change;
184 $data{$file}{BINARY
} = 1;
187 elsif (($adddel, $file) =
188 /^ (create|delete) mode [0-7]+ (.*)$/) {
189 $data{$file}{FILE_ADDDEL
} = $adddel;
193 for (sort keys %data) {
197 if ($only eq 'index-only') {
198 next if ($it->{INDEX
} eq 'unchanged');
200 if ($only eq 'file-only') {
201 next if ($it->{FILE
} eq 'nothing');
213 my ($string, @stuff) = @_;
215 for (my $i = 0; $i < @stuff; $i++) {
219 if ((ref $it) eq 'ARRAY') {
227 if ($it =~ /^$string/) {
231 if (defined $hit && defined $found) {
241 # inserts string into trie and updates count for each character
243 my ($trie, $string) = @_;
244 foreach (split //, $string) {
245 $trie = $trie->{$_} ||= {COUNT
=> 0};
250 # returns an array of tuples (prefix, remainder)
251 sub find_unique_prefixes
{
255 # any single prefix exceeding the soft limit is omitted
256 # if any prefix exceeds the hard limit all are omitted
257 # 0 indicates no limit
261 # build a trie modelling all possible options
263 foreach my $print (@stuff) {
264 if ((ref $print) eq 'ARRAY') {
265 $print = $print->[0];
267 elsif ((ref $print) eq 'HASH') {
268 $print = $print->{VALUE
};
270 update_trie
(\
%trie, $print);
271 push @return, $print;
274 # use the trie to find the unique prefixes
275 for (my $i = 0; $i < @return; $i++) {
276 my $ret = $return[$i];
277 my @letters = split //, $ret;
279 my ($prefix, $remainder);
281 for ($j = 0; $j < @letters; $j++) {
282 my $letter = $letters[$j];
283 if ($search{$letter}{COUNT
} == 1) {
284 $prefix = substr $ret, 0, $j + 1;
285 $remainder = substr $ret, $j + 1;
289 my $prefix = substr $ret, 0, $j;
291 if ($hard_limit && $j + 1 > $hard_limit);
293 %search = %{$search{$letter}};
295 if ($soft_limit && $j + 1 > $soft_limit) {
299 $return[$i] = [$prefix, $remainder];
304 # filters out prefixes which have special meaning to list_and_choose()
305 sub is_valid_prefix
{
307 return (defined $prefix) &&
308 !($prefix =~ /[\s,]/) && # separators
309 !($prefix =~ /^-/) && # deselection
310 !($prefix =~ /^\d+/) && # selection
311 ($prefix ne '*') && # "all" wildcard
312 ($prefix ne '?'); # prompt help
315 # given a prefix/remainder tuple return a string with the prefix highlighted
316 # for now use square brackets; later might use ANSI colors (underline, bold)
317 sub highlight_prefix
{
319 my $remainder = shift;
321 if (!defined $prefix) {
325 if (!is_valid_prefix
($prefix)) {
326 return "$prefix$remainder";
329 if (!$menu_use_color) {
330 return "[$prefix]$remainder";
333 return "$prompt_color$prefix$normal_color$remainder";
336 sub list_and_choose
{
337 my ($opts, @stuff) = @_;
338 my (@chosen, @return);
340 my @prefixes = find_unique_prefixes
(@stuff) unless $opts->{LIST_ONLY
};
346 if ($opts->{HEADER
}) {
347 if (!$opts->{LIST_FLAT
}) {
350 print colored
$header_color, "$opts->{HEADER}\n";
352 for ($i = 0; $i < @stuff; $i++) {
353 my $chosen = $chosen[$i] ?
'*' : ' ';
354 my $print = $stuff[$i];
355 my $ref = ref $print;
356 my $highlighted = highlight_prefix
(@
{$prefixes[$i]})
358 if ($ref eq 'ARRAY') {
359 $print = $highlighted || $print->[0];
361 elsif ($ref eq 'HASH') {
362 my $value = $highlighted || $print->{VALUE
};
363 $print = sprintf($status_fmt,
369 $print = $highlighted || $print;
371 printf("%s%2d: %s", $chosen, $i+1, $print);
372 if (($opts->{LIST_FLAT
}) &&
373 (($i + 1) % ($opts->{LIST_FLAT
}))) {
386 return if ($opts->{LIST_ONLY
});
388 print colored
$prompt_color, $opts->{PROMPT
};
389 if ($opts->{SINGLETON
}) {
398 $opts->{ON_EOF
}->() if $opts->{ON_EOF
};
405 singleton_prompt_help_cmd
() :
409 for my $choice (split(/[\s,]+/, $line)) {
413 # Input that begins with '-'; unchoose
414 if ($choice =~ s/^-//) {
417 # A range can be specified like 5-7 or 5-.
418 if ($choice =~ /^(\d+)-(\d*)$/) {
419 ($bottom, $top) = ($1, length($2) ?
$2 : 1 + @stuff);
421 elsif ($choice =~ /^\d+$/) {
422 $bottom = $top = $choice;
424 elsif ($choice eq '*') {
429 $bottom = $top = find_unique
($choice, @stuff);
430 if (!defined $bottom) {
431 print "Huh ($choice)?\n";
435 if ($opts->{SINGLETON
} && $bottom != $top) {
436 print "Huh ($choice)?\n";
439 for ($i = $bottom-1; $i <= $top-1; $i++) {
440 next if (@stuff <= $i || $i < 0);
441 $chosen[$i] = $choose;
444 last if ($opts->{IMMEDIATE
} || $line eq '*');
446 for ($i = 0; $i < @stuff; $i++) {
448 push @return, $stuff[$i];
454 sub singleton_prompt_help_cmd
{
455 print colored
$help_color, <<\EOF
;
457 1 - select a numbered item
458 foo
- select item based on unique prefix
459 - (empty
) select nothing
463 sub prompt_help_cmd
{
464 print colored
$help_color, <<\EOF
;
466 1 - select a single item
467 3-5 - select a range of items
468 2-3,6-9 - select multiple ranges
469 foo
- select item based on unique prefix
470 -... - unselect specified items
472 - (empty
) finish selecting
477 list_and_choose
({ LIST_ONLY
=> 1, HEADER
=> $status_head },
487 print "$cnt paths\n";
495 my @mods = list_modified
('file-only');
498 my @update = list_and_choose
({ PROMPT
=> 'Update',
499 HEADER
=> $status_head, },
502 system(qw(git update-index --add --remove --),
503 map { $_->{VALUE
} } @update);
504 say_n_paths
('updated', @update);
510 my @update = list_and_choose
({ PROMPT
=> 'Revert',
511 HEADER
=> $status_head, },
514 if (is_initial_commit
()) {
515 system(qw(git rm --cached),
516 map { $_->{VALUE
} } @update);
519 my @lines = run_cmd_pipe
(qw(git ls-tree HEAD --),
520 map { $_->{VALUE
} } @update);
522 open $fh, '| git update-index --index-info'
529 if ($_->{INDEX_ADDDEL
} &&
530 $_->{INDEX_ADDDEL
} eq 'create') {
531 system(qw(git update-index --force-remove --),
533 print "note: $_->{VALUE} is untracked now.\n";
538 say_n_paths
('reverted', @update);
543 sub add_untracked_cmd
{
544 my @add = list_and_choose
({ PROMPT
=> 'Add untracked' },
547 system(qw(git update-index --add --), @add);
548 say_n_paths
('added', @add);
555 my @diff = run_cmd_pipe
(qw(git diff-files -p --), $path);
557 if ($diff_use_color) {
558 @colored = run_cmd_pipe
(qw(git diff-files -p --color --), $path);
560 my (@hunk) = { TEXT
=> [], DISPLAY
=> [] };
562 for (my $i = 0; $i < @diff; $i++) {
563 if ($diff[$i] =~ /^@@ /) {
564 push @hunk, { TEXT
=> [], DISPLAY
=> [] };
566 push @
{$hunk[-1]{TEXT
}}, $diff[$i];
567 push @
{$hunk[-1]{DISPLAY
}},
568 ($diff_use_color ?
$colored[$i] : $diff[$i]);
573 sub parse_diff_header
{
576 my $head = { TEXT
=> [], DISPLAY
=> [] };
577 my $mode = { TEXT
=> [], DISPLAY
=> [] };
579 for (my $i = 0; $i < @
{$src->{TEXT
}}; $i++) {
580 my $dest = $src->{TEXT
}->[$i] =~ /^(old|new) mode (\d+)$/ ?
582 push @
{$dest->{TEXT
}}, $src->{TEXT
}->[$i];
583 push @
{$dest->{DISPLAY
}}, $src->{DISPLAY
}->[$i];
585 return ($head, $mode);
588 sub hunk_splittable
{
591 my @s = split_hunk
($text);
595 sub parse_hunk_header
{
597 my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
598 $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
599 $o_cnt = 1 unless defined $o_cnt;
600 $n_cnt = 1 unless defined $n_cnt;
601 return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
605 my ($text, $display) = @_;
607 if (!defined $display) {
610 # If there are context lines in the middle of a hunk,
611 # it can be split, but we would need to take care of
614 my ($o_ofs, undef, $n_ofs) = parse_hunk_header
($text->[0]);
619 my $next_hunk_start = undef;
620 my $i = $hunk_start - 1;
633 while (++$i < @
$text) {
634 my $line = $text->[$i];
635 my $display = $display->[$i];
637 if ($this->{ADDDEL
} &&
638 !defined $next_hunk_start) {
639 # We have seen leading context and
640 # adds/dels and then here is another
641 # context, which is trailing for this
642 # split hunk and leading for the next
644 $next_hunk_start = $i;
646 push @
{$this->{TEXT
}}, $line;
647 push @
{$this->{DISPLAY
}}, $display;
650 if (defined $next_hunk_start) {
657 if (defined $next_hunk_start) {
658 # We are done with the current hunk and
659 # this is the first real change for the
661 $hunk_start = $next_hunk_start;
662 $o_ofs = $this->{OLD
} + $this->{OCNT
};
663 $n_ofs = $this->{NEW
} + $this->{NCNT
};
664 $o_ofs -= $this->{POSTCTX
};
665 $n_ofs -= $this->{POSTCTX
};
669 push @
{$this->{TEXT
}}, $line;
670 push @
{$this->{DISPLAY
}}, $display;
684 for my $hunk (@split) {
685 $o_ofs = $hunk->{OLD
};
686 $n_ofs = $hunk->{NEW
};
687 my $o_cnt = $hunk->{OCNT
};
688 my $n_cnt = $hunk->{NCNT
};
690 my $head = ("@@ -$o_ofs" .
691 (($o_cnt != 1) ?
",$o_cnt" : '') .
693 (($n_cnt != 1) ?
",$n_cnt" : '') .
695 my $display_head = $head;
696 unshift @
{$hunk->{TEXT
}}, $head;
697 if ($diff_use_color) {
698 $display_head = colored
($fraginfo_color, $head);
700 unshift @
{$hunk->{DISPLAY
}}, $display_head;
708 colored
((/^@/ ?
$fraginfo_color :
709 /^\+/ ?
$diff_new_color :
710 /^-/ ?
$diff_old_color :
716 sub edit_hunk_manually
{
719 my $hunkfile = $repo->repo_path . "/addp-hunk-edit.diff";
721 open $fh, '>', $hunkfile
722 or die "failed to open hunk edit file for writing: " . $!;
723 print $fh "# Manual hunk edit mode -- see bottom for a quick guide\n";
727 # To remove '-' lines, make them ' ' lines (context).
728 # To remove '+' lines, delete them.
729 # Lines starting with # will be removed.
731 # If the patch applies cleanly, the edited hunk will immediately be
732 # marked for staging. If it does not apply cleanly, you will be given
733 # an opportunity to edit again. If all lines of the hunk are removed,
734 # then the edit is aborted and the hunk is left unchanged.
738 my $editor = $ENV{GIT_EDITOR
} || $repo->config("core.editor")
739 || $ENV{VISUAL
} || $ENV{EDITOR
} || "vi";
740 system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
742 open $fh, '<', $hunkfile
743 or die "failed to open hunk edit file for reading: " . $!;
744 my @newtext = grep { !/^#/ } <$fh>;
748 # Abort if nothing remains
749 if (!grep { /\S/ } @newtext) {
753 # Reinsert the first hunk header if the user accidentally deleted it
754 if ($newtext[0] !~ /^@/) {
755 unshift @newtext, $oldtext->[0];
762 open $fh, '| git apply --recount --cached --check';
764 print $fh @
{$h->{TEXT
}};
769 sub _restore_terminal_and_die
{
775 sub prompt_single_character
{
777 local $SIG{TERM
} = \
&_restore_terminal_and_die
;
778 local $SIG{INT
} = \
&_restore_terminal_and_die
;
782 print "$key" if defined $key;
793 print colored
$prompt_color, $prompt;
794 my $line = prompt_single_character
;
795 return 0 if $line =~ /^n/i;
796 return 1 if $line =~ /^y/i;
801 my ($head, $hunk, $ix) = @_;
802 my $text = $hunk->[$ix]->{TEXT
};
805 $text = edit_hunk_manually
($text);
806 if (!defined $text) {
809 my $newhunk = { TEXT
=> $text, USE
=> 1 };
810 if (diff_applies
($head,
813 @
{$hunk}[$ix+1..$#{$hunk}])) {
814 $newhunk->{DISPLAY
} = [color_diff
(@
{$text})];
819 'Your edited hunk does not apply. Edit again '
820 . '(saying "no" discards!) [y/n]? '
827 print colored
$help_color, <<\EOF
;
829 n
- do not stage this hunk
830 a
- stage this
and all the remaining hunks
in the file
831 d
- do not stage this hunk nor any of the remaining hunks
in the file
832 g
- select a hunk to go to
833 / - search
for a hunk matching the
given regex
834 j
- leave this hunk undecided
, see
next undecided hunk
835 J
- leave this hunk undecided
, see
next hunk
836 k
- leave this hunk undecided
, see previous undecided hunk
837 K
- leave this hunk undecided
, see previous hunk
838 s
- split the current hunk into smaller hunks
839 e
- manually edit the current hunk
844 sub patch_update_cmd
{
845 my @all_mods = list_modified
('file-only');
846 my @mods = grep { !($_->{BINARY
}) } @all_mods;
851 print STDERR
"Only binary files changed.\n";
853 print STDERR
"No changes.\n";
861 @them = list_and_choose
({ PROMPT
=> 'Patch update',
862 HEADER
=> $status_head, },
866 patch_update_file
($_->{VALUE
});
870 # Generate a one line summary of a hunk.
873 my $summary = $rhunk->{TEXT
}[0];
875 # Keep the line numbers, discard extra context.
876 $summary =~ s/@@(.*?)@@.*/$1 /s;
877 $summary .= " " x
(20 - length $summary);
879 # Add some user context.
880 for my $line (@
{$rhunk->{TEXT
}}) {
881 if ($line =~ m/^[+-].*\w/) {
888 return substr($summary, 0, 80) . "\n";
892 # Print a one-line summary of each hunk in the array ref in
893 # the first argument, starting wih the index in the 2nd.
895 my ($hunks, $i) = @_;
898 for (; $i < @
$hunks && $ctr < 20; $i++, $ctr++) {
900 if (defined $hunks->[$i]{USE
}) {
901 $status = $hunks->[$i]{USE
} ?
"+" : "-";
906 summarize_hunk
($hunks->[$i]);
911 sub patch_update_file
{
914 my ($head, @hunk) = parse_diff
($path);
915 ($head, my $mode) = parse_diff_header
($head);
916 for (@
{$head->{DISPLAY
}}) {
920 if (@
{$mode->{TEXT
}}) {
922 print @
{$mode->{DISPLAY
}};
923 print colored
$prompt_color,
924 "Stage mode change [y/n/a/d/?]? ";
925 my $line = prompt_single_character
;
926 if ($line =~ /^y/i) {
930 elsif ($line =~ /^n/i) {
934 elsif ($line =~ /^a/i) {
935 $_->{USE
} = 1 foreach ($mode, @hunk);
938 elsif ($line =~ /^d/i) {
939 $_->{USE
} = 0 foreach ($mode, @hunk);
953 my ($prev, $next, $other, $undecided, $i);
959 for ($i = 0; $i < $ix; $i++) {
960 if (!defined $hunk[$i]{USE
}) {
969 for ($i = $ix + 1; $i < $num; $i++) {
970 if (!defined $hunk[$i]{USE
}) {
976 if ($ix < $num - 1) {
982 for ($i = 0; $i < $num; $i++) {
983 if (!defined $hunk[$i]{USE
}) {
988 last if (!$undecided);
990 if (hunk_splittable
($hunk[$ix]{TEXT
})) {
994 for (@
{$hunk[$ix]{DISPLAY
}}) {
997 print colored
$prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
998 my $line = prompt_single_character
;
1000 if ($line =~ /^y/i) {
1001 $hunk[$ix]{USE
} = 1;
1003 elsif ($line =~ /^n/i) {
1004 $hunk[$ix]{USE
} = 0;
1006 elsif ($line =~ /^a/i) {
1007 while ($ix < $num) {
1008 if (!defined $hunk[$ix]{USE
}) {
1009 $hunk[$ix]{USE
} = 1;
1015 elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1017 my $no = $ix > 10 ?
$ix - 10 : 0;
1018 while ($response eq '') {
1020 $no = display_hunks
(\
@hunk, $no);
1022 $extra = " (<ret> to see more)";
1024 print "go to which hunk$extra? ";
1025 $response = <STDIN
>;
1026 if (!defined $response) {
1031 if ($response !~ /^\s*\d+\s*$/) {
1032 print STDERR
"Invalid number: '$response'\n";
1033 } elsif (0 < $response && $response <= $num) {
1034 $ix = $response - 1;
1036 print STDERR
"Sorry, only $num hunks available.\n";
1040 elsif ($line =~ /^d/i) {
1041 while ($ix < $num) {
1042 if (!defined $hunk[$ix]{USE
}) {
1043 $hunk[$ix]{USE
} = 0;
1049 elsif ($line =~ m
|^/(.*)|) {
1052 print colored
$prompt_color, "search for regex? ";
1054 if (defined $regex) {
1060 $search_string = qr{$regex}m;
1063 my ($err,$exp) = ($@
, $1);
1064 $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1065 print STDERR
"Malformed search regexp $exp: $err\n";
1070 my $text = join ("", @
{$hunk[$iy]{TEXT
}});
1071 last if ($text =~ $search_string);
1073 $iy = 0 if ($iy >= $num);
1075 print STDERR
"No hunk matches the given pattern\n";
1082 elsif ($line =~ /^K/) {
1083 if ($other =~ /K/) {
1087 print STDERR
"No previous hunk\n";
1091 elsif ($line =~ /^J/) {
1092 if ($other =~ /J/) {
1096 print STDERR
"No next hunk\n";
1100 elsif ($line =~ /^k/) {
1101 if ($other =~ /k/) {
1105 !defined $hunk[$ix]{USE
});
1109 print STDERR
"No previous hunk\n";
1113 elsif ($line =~ /^j/) {
1114 if ($other !~ /j/) {
1115 print STDERR
"No next hunk\n";
1119 elsif ($other =~ /s/ && $line =~ /^s/) {
1120 my @split = split_hunk
($hunk[$ix]{TEXT
}, $hunk[$ix]{DISPLAY
});
1122 print colored
$header_color, "Split into ",
1123 scalar(@split), " hunks.\n";
1125 splice (@hunk, $ix, 1, @split);
1126 $num = scalar @hunk;
1129 elsif ($line =~ /^e/) {
1130 my $newhunk = edit_hunk_loop
($head, \
@hunk, $ix);
1131 if (defined $newhunk) {
1132 splice @hunk, $ix, 1, $newhunk;
1136 help_patch_cmd
($other);
1142 last if ($ix >= $num ||
1143 !defined $hunk[$ix]{USE
});
1151 push @result, @
{$mode->{TEXT
}};
1155 push @result, @
{$_->{TEXT
}};
1162 open $fh, '| git apply --cached --recount';
1163 for (@
{$head->{TEXT
}}, @result) {
1167 for (@
{$head->{TEXT
}}, @result) {
1178 my @mods = list_modified
('index-only');
1179 @mods = grep { !($_->{BINARY
}) } @mods;
1181 my (@them) = list_and_choose
({ PROMPT
=> 'Review diff',
1183 HEADER
=> $status_head, },
1186 my $reference = is_initial_commit
() ? get_empty_tree
() : 'HEAD';
1187 system(qw(git diff -p --cached), $reference, '--',
1188 map { $_->{VALUE
} } @them);
1197 print colored
$help_color, <<\EOF
;
1198 status
- show paths with changes
1199 update
- add working tree
state to the staged set of changes
1200 revert
- revert staged set of changes back to the HEAD version
1201 patch
- pick hunks
and update selectively
1202 diff
- view diff between HEAD
and index
1203 add untracked
- add contents of untracked files to the staged set of changes
1208 return unless @ARGV;
1209 my $arg = shift @ARGV;
1210 if ($arg eq "--patch") {
1212 $arg = shift @ARGV or die "missing --";
1213 die "invalid argument $arg, expecting --"
1214 unless $arg eq "--";
1216 elsif ($arg ne "--") {
1217 die "invalid argument $arg, expecting --";
1222 my @cmd = ([ 'status', \
&status_cmd
, ],
1223 [ 'update', \
&update_cmd
, ],
1224 [ 'revert', \
&revert_cmd
, ],
1225 [ 'add untracked', \
&add_untracked_cmd
, ],
1226 [ 'patch', \
&patch_update_cmd
, ],
1227 [ 'diff', \
&diff_cmd
, ],
1228 [ 'quit', \
&quit_cmd
, ],
1229 [ 'help', \
&help_cmd
, ],
1232 my ($it) = list_and_choose
({ PROMPT
=> 'What now',
1235 HEADER
=> '*** Commands ***',
1236 ON_EOF
=> \
&quit_cmd
,
1237 IMMEDIATE
=> 1 }, @cmd);