Skip to content

Commit a9c4641

Browse files
0xAXgitster
authored andcommitted
add -i: return from list_and_choose if there is no candidate
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit a9c4641

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

git-add--interactive.perl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ sub error_msg {
515515
sub list_and_choose {
516516
my ($opts, @stuff) = @_;
517517
my (@chosen, @return);
518+
if (!@stuff) {
519+
return @return;
520+
}
518521
my $i;
519522
my @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY};
520523

@@ -725,6 +728,8 @@ sub add_untracked_cmd {
725728
if (@add) {
726729
system(qw(git update-index --add --), @add);
727730
say_n_paths('added', @add);
731+
} else {
732+
print "No untracked files.\n";
728733
}
729734
print "\n";
730735
}

0 commit comments

Comments
 (0)