Skip to content

Commit

Permalink
add -i: return from list_and_choose if there is no candidate
Browse files Browse the repository at this point in the history
The list_and_choose() helper is given a prompt and a list, asks the
user to make selection from the list, and then returns a list of
items chosen.  Even when it is given an empty list as the original
candidate set to choose from, it gave a prompt to the user, who can
only say "I am done choosing".

Return an empty result when the input is an empty list without
bothering the user.  The existing caller must already have a logic
to say "Nothing to do" or an equivalent when the returned list is
empty (i.e. the user chose to select nothing) if it is necessary, so
no change to the callers is necessary.

This fixes the case where "add untracked" is asked in "git add -i"
and there is no untracked files in the working tree.  We used to give
an empty list of files to choose from with a prompt, but with this
change, we no longer do.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Alexander Kuleshov authored and Junio C Hamano committed Jan 22, 2015
1 parent 282616c commit a9c4641
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ sub error_msg {
sub list_and_choose {
my ($opts, @stuff) = @_;
my (@chosen, @return);
if (!@stuff) {
return @return;
}
my $i;
my @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY};

Expand Down Expand Up @@ -725,6 +728,8 @@ sub add_untracked_cmd {
if (@add) {
system(qw(git update-index --add --), @add);
say_n_paths('added', @add);
} else {
print "No untracked files.\n";
}
print "\n";
}
Expand Down

0 comments on commit a9c4641

Please sign in to comment.