Skip to contentSkip to conversation

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

PATCH In review Alexander Kuleshov 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-add--interactive: print message if there are no untracked files

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.

---
 git-add--interactive.perl | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
git-add--interactive.perl +9 -5
index 94b988c..1a6dcf3 100755
@@ -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";
 }
Signature · 1 line
2.3.0.rc1.247.gb53aa6f
#1 lore raw
Quoted 4 lines · Alexander Kuleshov

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.

Quoted 10 lines
---
 git-add--interactive.perl | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
git-add--interactive.perl +0 -0
index 94b988c..1a6dcf3 100755

git-add--interactive.perl sub revert_cmd { · line 727

Quoted 9 lines
git-add--interactive.perl +1 -5
@@ -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?

Quoted 11 lines
git-add--interactive.perl +8 -0
+		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 lore raw
Quoted 11 lines · Junio C Hamano

Review

Quoted 7 lines

sub add_untracked_cmd {

(quoted diff) +1 -5
-	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.

Quoted 3 lines

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(+)
git-add--interactive.perl +4 -0
index 94b988c..46ed9a7 100755
@@ -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};
 
#3 lore raw

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 <[email protected]>:

Quoted 41 lines
Quoted 8 lines · Junio C Hamano

Review

Quoted 7 lines

sub add_untracked_cmd {

(quoted diff) +1 -5
-    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 --))) {
Quoted 6 lines

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(+)
git-add--interactive.perl +4 -0
index 94b988c..46ed9a7 100755
@@ -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};
 
Signature · 2 lines
_________________________
0xAX