threads / patch / 38421

patchgit-add--interactive: print message if there are no untracked files

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

## tl;dr

4 messages between Jan 21, 2015 and Jan 22, 2015. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Alexander Kuleshov· Jan 21, 2015, 19:03 UTC · lore

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(-)
Show changes to git-add--interactive.perl +9 −5
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· Jan 21, 2015, 21:11 UTC · re: Alexander Kuleshov · lore

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

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.
Show 19 quoted lines
> 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?
Show 11 quoted lines
> +		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· Jan 21, 2015, 21:17 UTC · re: Junio C Hamano · lore

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

Junio C Hamano <gitster@pobox.com> writes:
Show 14 quoted lines
>>  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(+)
Show changes to git-add--interactive.perl +4 −0
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· Jan 22, 2015, 07:11 UTC · re: Junio C Hamano · lore

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

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>:
Show 41 quoted lines
> 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

← back to recent threads