# [PATCH] git-add--interactive: print message if there are no untracked files

4 messages from 2015-01-21 to 2015-01-22. Participants: Alexander Kuleshov, Junio C Hamano.
Thread: https://gitlist.dev/t/38421

## Alexander Kuleshov, 2015-01-21 19:03

Subject: [PATCH] git-add--interactive: print message if there are no untracked files
Message-ID: <1421867004-31672-1-git-send-email-kuleshovmail@gmail.com>
URL: https://gitlist.dev/e/1421867004-31672-1-git-send-email-kuleshovmail%40gmail.com

```
If user selects 'add untracked' and there are no untracked files,
"Add untracked>>" opens. But it does not make sense in this case, because there
are no untracked files. So let's print message and exit from "add untracked" mode.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 git-add--interactive.perl | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 94b988c..1a6dcf3 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -724,11 +724,15 @@ sub revert_cmd {
 }
 
 sub add_untracked_cmd {
-	my @add = list_and_choose({ PROMPT => 'Add untracked' },
-				  list_untracked());
-	if (@add) {
-		system(qw(git update-index --add --), @add);
-		say_n_paths('added', @add);
+	if (system(qw(git ls-files --others --exclude-standard --))) {
+		my @add = list_and_choose({ PROMPT => 'Add untracked' },
+					  list_untracked());
+		if (@add) {
+			system(qw(git update-index --add --), @add);
+			say_n_paths('added', @add);
+		}
+	} else {
+		print "No untracked files.\n";
 	}
 	print "\n";
 }
-- 
2.3.0.rc1.247.gb53aa6f

```

## Junio C Hamano, 2015-01-21 21:11

Subject: Re: [PATCH] git-add--interactive: print message if there are no untracked files
Message-ID: <xmqqmw5bx2ii.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqmw5bx2ii.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1421867004-31672-1-git-send-email-kuleshovmail@gmail.com>

```
Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> If user selects 'add untracked' and there are no untracked files,
> "Add untracked>>" opens. But it does not make sense in this case,
> because there are no untracked files. So let's print message and
> exit from "add untracked" mode.

That reasoning makes perfect sense.

> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
>  git-add--interactive.perl | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 94b988c..1a6dcf3 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -724,11 +724,15 @@ sub revert_cmd {
>  }
>  
>  sub add_untracked_cmd {
> -	my @add = list_and_choose({ PROMPT => 'Add untracked' },
> -				  list_untracked());
> -	if (@add) {
> -		system(qw(git update-index --add --), @add);
> -		say_n_paths('added', @add);
> +	if (system(qw(git ls-files --others --exclude-standard --))) {

But this ls-files invocation that knows too much about how
list_untracked() computes things does not.

Why not

	my @add = list_untracked();
        if (@add) {
        	@add = list_and_choose({...}, @add);
	}
        if (!@add) {
		Nothing to do;
	} else {
		Run update-index
	}

or something instead?

> +		my @add = list_and_choose({ PROMPT => 'Add untracked' },
> +					  list_untracked());
> +		if (@add) {
> +			system(qw(git update-index --add --), @add);
> +			say_n_paths('added', @add);
> +		}
> +	} else {
> +		print "No untracked files.\n";
>  	}
>  	print "\n";
>  }

```

## Junio C Hamano, 2015-01-21 21:17

Subject: Re: [PATCH] git-add--interactive: print message if there are no untracked files
Message-ID: <xmqqegqnx281.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqegqnx281.fsf%40gitster.dls.corp.google.com
In-Reply-To: <xmqqmw5bx2ii.fsf@gitster.dls.corp.google.com>

```
Junio C Hamano <gitster@pobox.com> writes:

>>  sub add_untracked_cmd {
>> -	my @add = list_and_choose({ PROMPT => 'Add untracked' },
>> -				  list_untracked());
>> -	if (@add) {
>> -		system(qw(git update-index --add --), @add);
>> -		say_n_paths('added', @add);
>> +	if (system(qw(git ls-files --others --exclude-standard --))) {
>
> But this ls-files invocation that knows too much about how
> list_untracked() computes things does not.
>
> Why not
> ...
> or something instead?

Actually, is there any case where list_and_choose() should give a
prompt to choose from zero candidates?

In other words, I am wondering if this affects other callers of
list_and_choose in any negative way.

 git-add--interactive.perl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 94b988c..46ed9a7 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -519,6 +519,10 @@ 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};
 

```

## Alexander Kuleshov, 2015-01-22 07:11

Subject: Re: [PATCH] git-add--interactive: print message if there are no untracked files
Message-ID: <CANCZXo5OQHNCyz3kUY6c0Y_Lpabee0WS+eQ5G53QupMLwOw=jg@mail.gmail.com>
URL: https://gitlist.dev/e/CANCZXo5OQHNCyz3kUY6c0Y_Lpabee0WS%2BeQ5G53QupMLwOw%3Djg%40mail.gmail.com
In-Reply-To: <xmqqegqnx281.fsf@gitster.dls.corp.google.com>

```
No i don't see any reasons why list_and_choose() shoud give a prompt
without candidates. Will resed patch.

Thank you.

2015-01-22 3:17 GMT+06:00 Junio C Hamano <gitster@pobox.com>:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>>  sub add_untracked_cmd {
>>> -    my @add = list_and_choose({ PROMPT => 'Add untracked' },
>>> -                              list_untracked());
>>> -    if (@add) {
>>> -            system(qw(git update-index --add --), @add);
>>> -            say_n_paths('added', @add);
>>> +    if (system(qw(git ls-files --others --exclude-standard --))) {
>>
>> But this ls-files invocation that knows too much about how
>> list_untracked() computes things does not.
>>
>> Why not
>> ...
>> or something instead?
>
> Actually, is there any case where list_and_choose() should give a
> prompt to choose from zero candidates?
>
> In other words, I am wondering if this affects other callers of
> list_and_choose in any negative way.
>
>  git-add--interactive.perl | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 94b988c..46ed9a7 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -519,6 +519,10 @@ 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};
>



-- 
_________________________
0xAX

```
