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");
43 if ($repo->config_bool("interactive.singlekey")) {
52 my $string = join("", @_);
55 # Put a color code at the beginning of each line, a reset at the end
56 # color after newlines that are not at the end of the string
57 $string =~ s/(\n+)(.)/$1$color$2/g;
58 # reset before newlines
59 $string =~ s/(\n+)/$normal_color$1/g;
60 # codes at beginning and end (if necessary):
61 $string =~ s/^/$color/;
62 $string =~ s/$/$normal_color/ unless $string =~ /\n$/;
67 # command line options
71 if ($^O eq 'MSWin32' || $^O eq 'msys') {
72 my @invalid = grep {m/[":*]/} @_;
73 die "$^O does not support: @invalid\n" if @invalid;
74 my @args = map { m/ /o ? "\"$_\"": $_ } @_;
78 open($fh, '-|', @_) or die;
83 my ($GIT_DIR) = run_cmd_pipe(qw(git rev-parse --git-dir));
85 if (!defined $GIT_DIR) {
86 exit(1); # rev-parse would have already said "not a git repo"
92 open $fh, 'git update-index --refresh |'
95 ;# ignore 'needs update'
105 run_cmd_pipe(qw(git ls-files --others --exclude-standard --), @ARGV);
108 my $status_fmt = '%12s %12s %s';
109 my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
113 sub is_initial_commit {
114 $initial = system('git rev-parse HEAD -- >/dev/null 2>&1') != 0
115 unless defined $initial;
121 return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
124 # Returns list of hashes, contents of each of which are:
126 # BINARY: is a binary path
127 # INDEX: is index different from HEAD?
128 # FILE: is file different from index?
129 # INDEX_ADDDEL: is it add/delete between HEAD and index?
130 # FILE_ADDDEL: is it add/delete between index and file?
135 my ($add, $del, $adddel, $file);
141 } run_cmd_pipe(qw(git ls-files --exclude-standard --), @ARGV);
142 return if (!@tracked);
145 my $reference = is_initial_commit() ? get_empty_tree() : 'HEAD';
146 for (run_cmd_pipe(qw(git diff-index --cached
147 --numstat --summary), $reference,
149 if (($add, $del, $file) =
150 /^([-\d]+) ([-\d]+) (.*)/) {
152 if ($add eq '-' && $del eq '-') {
157 $change = "+$add/-$del";
165 elsif (($adddel, $file) =
166 /^ (create|delete) mode [0-7]+ (.*)$/) {
167 $data{$file}{INDEX_ADDDEL} = $adddel;
171 for (run_cmd_pipe(qw(git diff-files --numstat --summary --), @tracked)) {
172 if (($add, $del, $file) =
173 /^([-\d]+) ([-\d]+) (.*)/) {
174 if (!exists $data{$file}) {
176 INDEX => 'unchanged',
181 if ($add eq '-' && $del eq '-') {
186 $change = "+$add/-$del";
188 $data{$file}{FILE} = $change;
190 $data{$file}{BINARY} = 1;
193 elsif (($adddel, $file) =
194 /^ (create|delete) mode [0-7]+ (.*)$/) {
195 $data{$file}{FILE_ADDDEL} = $adddel;
199 for (sort keys %data) {
203 if ($only eq 'index-only') {
204 next if ($it->{INDEX} eq 'unchanged');
206 if ($only eq 'file-only') {
207 next if ($it->{FILE} eq 'nothing');
219 my ($string, @stuff) = @_;
221 for (my $i = 0; $i < @stuff; $i++) {
225 if ((ref $it) eq 'ARRAY') {
233 if ($it =~ /^$string/) {
237 if (defined $hit && defined $found) {
247 # inserts string into trie and updates count for each character
249 my ($trie, $string) = @_;
250 foreach (split //, $string) {
251 $trie = $trie->{$_} ||= {COUNT => 0};
256 # returns an array of tuples (prefix, remainder)
257 sub find_unique_prefixes {
261 # any single prefix exceeding the soft limit is omitted
262 # if any prefix exceeds the hard limit all are omitted
263 # 0 indicates no limit
267 # build a trie modelling all possible options
269 foreach my $print (@stuff) {
270 if ((ref $print) eq 'ARRAY') {
271 $print = $print->[0];
273 elsif ((ref $print) eq 'HASH') {
274 $print = $print->{VALUE};
276 update_trie(\%trie, $print);
277 push @return, $print;
280 # use the trie to find the unique prefixes
281 for (my $i = 0; $i < @return; $i++) {
282 my $ret = $return[$i];
283 my @letters = split //, $ret;
285 my ($prefix, $remainder);
287 for ($j = 0; $j < @letters; $j++) {
288 my $letter = $letters[$j];
289 if ($search{$letter}{COUNT} == 1) {
290 $prefix = substr $ret, 0, $j + 1;
291 $remainder = substr $ret, $j + 1;
295 my $prefix = substr $ret, 0, $j;
297 if ($hard_limit && $j + 1 > $hard_limit);
299 %search = %{$search{$letter}};
301 if ($soft_limit && $j + 1 > $soft_limit) {
305 $return[$i] = [$prefix, $remainder];
310 # filters out prefixes which have special meaning to list_and_choose()
311 sub is_valid_prefix {
313 return (defined $prefix) &&
314 !($prefix =~ /[\s,]/) && # separators
315 !($prefix =~ /^-/) && # deselection
316 !($prefix =~ /^\d+/) && # selection
317 ($prefix ne '*') && # "all" wildcard
318 ($prefix ne '?'); # prompt help
321 # given a prefix/remainder tuple return a string with the prefix highlighted
322 # for now use square brackets; later might use ANSI colors (underline, bold)
323 sub highlight_prefix {
325 my $remainder = shift;
327 if (!defined $prefix) {
331 if (!is_valid_prefix($prefix)) {
332 return "$prefix$remainder";
335 if (!$menu_use_color) {
336 return "[$prefix]$remainder";
339 return "$prompt_color$prefix$normal_color$remainder";
343 print STDERR colored $error_color, @_;
346 sub list_and_choose {
347 my ($opts, @stuff) = @_;
348 my (@chosen, @return);
350 my @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY};
356 if ($opts->{HEADER}) {
357 if (!$opts->{LIST_FLAT}) {
360 print colored $header_color, "$opts->{HEADER}\n";
362 for ($i = 0; $i < @stuff; $i++) {
363 my $chosen = $chosen[$i] ? '*' : ' ';
364 my $print = $stuff[$i];
365 my $ref = ref $print;
366 my $highlighted = highlight_prefix(@{$prefixes[$i]})
368 if ($ref eq 'ARRAY') {
369 $print = $highlighted || $print->[0];
371 elsif ($ref eq 'HASH') {
372 my $value = $highlighted || $print->{VALUE};
373 $print = sprintf($status_fmt,
379 $print = $highlighted || $print;
381 printf("%s%2d: %s", $chosen, $i+1, $print);
382 if (($opts->{LIST_FLAT}) &&
383 (($i + 1) % ($opts->{LIST_FLAT}))) {
396 return if ($opts->{LIST_ONLY});
398 print colored $prompt_color, $opts->{PROMPT};
399 if ($opts->{SINGLETON}) {
408 $opts->{ON_EOF}->() if $opts->{ON_EOF};
415 singleton_prompt_help_cmd() :
419 for my $choice (split(/[\s,]+/, $line)) {
423 # Input that begins with '-'; unchoose
424 if ($choice =~ s/^-//) {
427 # A range can be specified like 5-7 or 5-.
428 if ($choice =~ /^(\d+)-(\d*)$/) {
429 ($bottom, $top) = ($1, length($2) ? $2 : 1 + @stuff);
431 elsif ($choice =~ /^\d+$/) {
432 $bottom = $top = $choice;
434 elsif ($choice eq '*') {
439 $bottom = $top = find_unique($choice, @stuff);
440 if (!defined $bottom) {
441 error_msg "Huh ($choice)?\n";
445 if ($opts->{SINGLETON} && $bottom != $top) {
446 error_msg "Huh ($choice)?\n";
449 for ($i = $bottom-1; $i <= $top-1; $i++) {
450 next if (@stuff <= $i || $i < 0);
451 $chosen[$i] = $choose;
454 last if ($opts->{IMMEDIATE} || $line eq '*');
456 for ($i = 0; $i < @stuff; $i++) {
458 push @return, $stuff[$i];
464 sub singleton_prompt_help_cmd {
465 print colored $help_color, <<\EOF ;
467 1 - select a numbered item
468 foo - select item based on unique prefix
469 - (empty) select nothing
473 sub prompt_help_cmd {
474 print colored $help_color, <<\EOF ;
476 1 - select a single item
477 3-5 - select a range of items
478 2-3,6-9 - select multiple ranges
479 foo - select item based on unique prefix
480 -... - unselect specified items
482 - (empty) finish selecting
487 list_and_choose({ LIST_ONLY => 1, HEADER => $status_head },
497 print "$cnt paths\n";
505 my @mods = list_modified('file-only');
508 my @update = list_and_choose({ PROMPT => 'Update',
509 HEADER => $status_head, },
512 system(qw(git update-index --add --remove --),
513 map { $_->{VALUE} } @update);
514 say_n_paths('updated', @update);
520 my @update = list_and_choose({ PROMPT => 'Revert',
521 HEADER => $status_head, },
524 if (is_initial_commit()) {
525 system(qw(git rm --cached),
526 map { $_->{VALUE} } @update);
529 my @lines = run_cmd_pipe(qw(git ls-tree HEAD --),
530 map { $_->{VALUE} } @update);
532 open $fh, '| git update-index --index-info'
539 if ($_->{INDEX_ADDDEL} &&
540 $_->{INDEX_ADDDEL} eq 'create') {
541 system(qw(git update-index --force-remove --),
543 print "note: $_->{VALUE} is untracked now.\n";
548 say_n_paths('reverted', @update);
553 sub add_untracked_cmd {
554 my @add = list_and_choose({ PROMPT => 'Add untracked' },
557 system(qw(git update-index --add --), @add);
558 say_n_paths('added', @add);
565 my @diff = run_cmd_pipe(qw(git diff-files -p --), $path);
567 if ($diff_use_color) {
568 @colored = run_cmd_pipe(qw(git diff-files -p --color --), $path);
570 my (@hunk) = { TEXT => [], DISPLAY => [] };
572 for (my $i = 0; $i < @diff; $i++) {
573 if ($diff[$i] =~ /^@@ /) {
574 push @hunk, { TEXT => [], DISPLAY => [] };
576 push @{$hunk[-1]{TEXT}}, $diff[$i];
577 push @{$hunk[-1]{DISPLAY}},
578 ($diff_use_color ? $colored[$i] : $diff[$i]);
583 sub parse_diff_header {
586 my $head = { TEXT => [], DISPLAY => [] };
587 my $mode = { TEXT => [], DISPLAY => [] };
589 for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
590 my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
592 push @{$dest->{TEXT}}, $src->{TEXT}->[$i];
593 push @{$dest->{DISPLAY}}, $src->{DISPLAY}->[$i];
595 return ($head, $mode);
598 sub hunk_splittable {
601 my @s = split_hunk($text);
605 sub parse_hunk_header {
607 my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
608 $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
609 $o_cnt = 1 unless defined $o_cnt;
610 $n_cnt = 1 unless defined $n_cnt;
611 return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
615 my ($text, $display) = @_;
617 if (!defined $display) {
620 # If there are context lines in the middle of a hunk,
621 # it can be split, but we would need to take care of
624 my ($o_ofs, undef, $n_ofs) = parse_hunk_header($text->[0]);
629 my $next_hunk_start = undef;
630 my $i = $hunk_start - 1;
643 while (++$i < @$text) {
644 my $line = $text->[$i];
645 my $display = $display->[$i];
647 if ($this->{ADDDEL} &&
648 !defined $next_hunk_start) {
649 # We have seen leading context and
650 # adds/dels and then here is another
651 # context, which is trailing for this
652 # split hunk and leading for the next
654 $next_hunk_start = $i;
656 push @{$this->{TEXT}}, $line;
657 push @{$this->{DISPLAY}}, $display;
660 if (defined $next_hunk_start) {
667 if (defined $next_hunk_start) {
668 # We are done with the current hunk and
669 # this is the first real change for the
671 $hunk_start = $next_hunk_start;
672 $o_ofs = $this->{OLD} + $this->{OCNT};
673 $n_ofs = $this->{NEW} + $this->{NCNT};
674 $o_ofs -= $this->{POSTCTX};
675 $n_ofs -= $this->{POSTCTX};
679 push @{$this->{TEXT}}, $line;
680 push @{$this->{DISPLAY}}, $display;
694 for my $hunk (@split) {
695 $o_ofs = $hunk->{OLD};
696 $n_ofs = $hunk->{NEW};
697 my $o_cnt = $hunk->{OCNT};
698 my $n_cnt = $hunk->{NCNT};
700 my $head = ("@@ -$o_ofs" .
701 (($o_cnt != 1) ? ",$o_cnt" : '') .
703 (($n_cnt != 1) ? ",$n_cnt" : '') .
705 my $display_head = $head;
706 unshift @{$hunk->{TEXT}}, $head;
707 if ($diff_use_color) {
708 $display_head = colored($fraginfo_color, $head);
710 unshift @{$hunk->{DISPLAY}}, $display_head;
718 colored((/^@/ ? $fraginfo_color :
719 /^\+/ ? $diff_new_color :
720 /^-/ ? $diff_old_color :
726 sub edit_hunk_manually {
729 my $hunkfile = $repo->repo_path . "/addp-hunk-edit.diff";
731 open $fh, '>', $hunkfile
732 or die "failed to open hunk edit file for writing: " . $!;
733 print $fh "# Manual hunk edit mode -- see bottom for a quick guide\n";
737 # To remove '-' lines, make them ' ' lines (context).
738 # To remove '+' lines, delete them.
739 # Lines starting with # will be removed.
741 # If the patch applies cleanly, the edited hunk will immediately be
742 # marked for staging. If it does not apply cleanly, you will be given
743 # an opportunity to edit again. If all lines of the hunk are removed,
744 # then the edit is aborted and the hunk is left unchanged.
748 my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor")
749 || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
750 system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
752 open $fh, '<', $hunkfile
753 or die "failed to open hunk edit file for reading: " . $!;
754 my @newtext = grep { !/^#/ } <$fh>;
758 # Abort if nothing remains
759 if (!grep { /\S/ } @newtext) {
763 # Reinsert the first hunk header if the user accidentally deleted it
764 if ($newtext[0] !~ /^@/) {
765 unshift @newtext, $oldtext->[0];
772 open $fh, '| git apply --recount --cached --check';
774 print $fh @{$h->{TEXT}};
779 sub _restore_terminal_and_die {
785 sub prompt_single_character {
787 local $SIG{TERM} = \&_restore_terminal_and_die;
788 local $SIG{INT} = \&_restore_terminal_and_die;
792 print "$key" if defined $key;
803 print colored $prompt_color, $prompt;
804 my $line = prompt_single_character;
805 return 0 if $line =~ /^n/i;
806 return 1 if $line =~ /^y/i;
811 my ($head, $hunk, $ix) = @_;
812 my $text = $hunk->[$ix]->{TEXT};
815 $text = edit_hunk_manually($text);
816 if (!defined $text) {
819 my $newhunk = { TEXT => $text, USE => 1 };
820 if (diff_applies($head,
823 @{$hunk}[$ix+1..$#{$hunk}])) {
824 $newhunk->{DISPLAY} = [color_diff(@{$text})];
829 'Your edited hunk does not apply. Edit again '
830 . '(saying "no" discards!) [y/n]? '
837 print colored $help_color, <<\EOF ;
839 n - do not stage this hunk
840 a - stage this and all the remaining hunks in the file
841 d - do not stage this hunk nor any of the remaining hunks in the file
842 g - select a hunk to go to
843 / - search for a hunk matching the given regex
844 j - leave this hunk undecided, see next undecided hunk
845 J - leave this hunk undecided, see next hunk
846 k - leave this hunk undecided, see previous undecided hunk
847 K - leave this hunk undecided, see previous hunk
848 s - split the current hunk into smaller hunks
849 e - manually edit the current hunk
854 sub patch_update_cmd {
855 my @all_mods = list_modified('file-only');
856 my @mods = grep { !($_->{BINARY}) } @all_mods;
861 print STDERR "Only binary files changed.\n";
863 print STDERR "No changes.\n";
871 @them = list_and_choose({ PROMPT => 'Patch update',
872 HEADER => $status_head, },
876 patch_update_file($_->{VALUE});
880 # Generate a one line summary of a hunk.
883 my $summary = $rhunk->{TEXT}[0];
885 # Keep the line numbers, discard extra context.
886 $summary =~ s/@@(.*?)@@.*/$1 /s;
887 $summary .= " " x (20 - length $summary);
889 # Add some user context.
890 for my $line (@{$rhunk->{TEXT}}) {
891 if ($line =~ m/^[+-].*\w/) {
898 return substr($summary, 0, 80) . "\n";
902 # Print a one-line summary of each hunk in the array ref in
903 # the first argument, starting wih the index in the 2nd.
905 my ($hunks, $i) = @_;
908 for (; $i < @$hunks && $ctr < 20; $i++, $ctr++) {
910 if (defined $hunks->[$i]{USE}) {
911 $status = $hunks->[$i]{USE} ? "+" : "-";
916 summarize_hunk($hunks->[$i]);
921 sub patch_update_file {
924 my ($head, @hunk) = parse_diff($path);
925 ($head, my $mode) = parse_diff_header($head);
926 for (@{$head->{DISPLAY}}) {
930 if (@{$mode->{TEXT}}) {
932 print @{$mode->{DISPLAY}};
933 print colored $prompt_color,
934 "Stage mode change [y/n/a/d/?]? ";
935 my $line = prompt_single_character;
936 if ($line =~ /^y/i) {
940 elsif ($line =~ /^n/i) {
944 elsif ($line =~ /^a/i) {
945 $_->{USE} = 1 foreach ($mode, @hunk);
948 elsif ($line =~ /^d/i) {
949 $_->{USE} = 0 foreach ($mode, @hunk);
963 my ($prev, $next, $other, $undecided, $i);
969 for ($i = 0; $i < $ix; $i++) {
970 if (!defined $hunk[$i]{USE}) {
979 for ($i = $ix + 1; $i < $num; $i++) {
980 if (!defined $hunk[$i]{USE}) {
986 if ($ix < $num - 1) {
992 for ($i = 0; $i < $num; $i++) {
993 if (!defined $hunk[$i]{USE}) {
998 last if (!$undecided);
1000 if (hunk_splittable($hunk[$ix]{TEXT})) {
1004 for (@{$hunk[$ix]{DISPLAY}}) {
1007 print colored $prompt_color, "Stage this hunk [y,n,a,d,/$other,?]? ";
1008 my $line = prompt_single_character;
1010 if ($line =~ /^y/i) {
1011 $hunk[$ix]{USE} = 1;
1013 elsif ($line =~ /^n/i) {
1014 $hunk[$ix]{USE} = 0;
1016 elsif ($line =~ /^a/i) {
1017 while ($ix < $num) {
1018 if (!defined $hunk[$ix]{USE}) {
1019 $hunk[$ix]{USE} = 1;
1025 elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1027 my $no = $ix > 10 ? $ix - 10 : 0;
1028 while ($response eq '') {
1030 $no = display_hunks(\@hunk, $no);
1032 $extra = " (<ret> to see more)";
1034 print "go to which hunk$extra? ";
1035 $response = <STDIN>;
1036 if (!defined $response) {
1041 if ($response !~ /^\s*\d+\s*$/) {
1042 error_msg "Invalid number: '$response'\n";
1043 } elsif (0 < $response && $response <= $num) {
1044 $ix = $response - 1;
1046 error_msg "Sorry, only $num hunks available.\n";
1050 elsif ($line =~ /^d/i) {
1051 while ($ix < $num) {
1052 if (!defined $hunk[$ix]{USE}) {
1053 $hunk[$ix]{USE} = 0;
1059 elsif ($line =~ m|^/(.*)|) {
1062 print colored $prompt_color, "search for regex? ";
1064 if (defined $regex) {
1070 $search_string = qr{$regex}m;
1073 my ($err,$exp) = ($@, $1);
1074 $err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1075 error_msg "Malformed search regexp $exp: $err\n";
1080 my $text = join ("", @{$hunk[$iy]{TEXT}});
1081 last if ($text =~ $search_string);
1083 $iy = 0 if ($iy >= $num);
1085 error_msg "No hunk matches the given pattern\n";
1092 elsif ($line =~ /^K/) {
1093 if ($other =~ /K/) {
1097 error_msg "No previous hunk\n";
1101 elsif ($line =~ /^J/) {
1102 if ($other =~ /J/) {
1106 error_msg "No next hunk\n";
1110 elsif ($line =~ /^k/) {
1111 if ($other =~ /k/) {
1115 !defined $hunk[$ix]{USE});
1119 error_msg "No previous hunk\n";
1123 elsif ($line =~ /^j/) {
1124 if ($other !~ /j/) {
1125 error_msg "No next hunk\n";
1129 elsif ($other =~ /s/ && $line =~ /^s/) {
1130 my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
1132 print colored $header_color, "Split into ",
1133 scalar(@split), " hunks.\n";
1135 splice (@hunk, $ix, 1, @split);
1136 $num = scalar @hunk;
1139 elsif ($line =~ /^e/) {
1140 my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
1141 if (defined $newhunk) {
1142 splice @hunk, $ix, 1, $newhunk;
1146 help_patch_cmd($other);
1152 last if ($ix >= $num ||
1153 !defined $hunk[$ix]{USE});
1161 push @result, @{$mode->{TEXT}};
1165 push @result, @{$_->{TEXT}};
1172 open $fh, '| git apply --cached --recount';
1173 for (@{$head->{TEXT}}, @result) {
1177 for (@{$head->{TEXT}}, @result) {
1188 my @mods = list_modified('index-only');
1189 @mods = grep { !($_->{BINARY}) } @mods;
1191 my (@them) = list_and_choose({ PROMPT => 'Review diff',
1193 HEADER => $status_head, },
1196 my $reference = is_initial_commit() ? get_empty_tree() : 'HEAD';
1197 system(qw(git diff -p --cached), $reference, '--',
1198 map { $_->{VALUE} } @them);
1207 print colored $help_color, <<\EOF ;
1208 status - show paths with changes
1209 update - add working tree state to the staged set of changes
1210 revert - revert staged set of changes back to the HEAD version
1211 patch - pick hunks and update selectively
1212 diff - view diff between HEAD and index
1213 add untracked - add contents of untracked files to the staged set of changes
1218 return unless @ARGV;
1219 my $arg = shift @ARGV;
1220 if ($arg eq "--patch") {
1222 $arg = shift @ARGV or die "missing --";
1223 die "invalid argument $arg, expecting --"
1224 unless $arg eq "--";
1226 elsif ($arg ne "--") {
1227 die "invalid argument $arg, expecting --";
1232 my @cmd = ([ 'status', \&status_cmd, ],
1233 [ 'update', \&update_cmd, ],
1234 [ 'revert', \&revert_cmd, ],
1235 [ 'add untracked', \&add_untracked_cmd, ],
1236 [ 'patch', \&patch_update_cmd, ],
1237 [ 'diff', \&diff_cmd, ],
1238 [ 'quit', \&quit_cmd, ],
1239 [ 'help', \&help_cmd, ],
1242 my ($it) = list_and_choose({ PROMPT => 'What now',
1245 HEADER => '*** Commands ***',
1246 ON_EOF => \&quit_cmd,
1247 IMMEDIATE => 1 }, @cmd);