{"thread":{"id":"38421","subject":"[PATCH] git-add--interactive: print message if there are no untracked files","startedAt":"2015-01-21T19:03:24Z","lastAt":"2015-01-22T07:11:37Z","messageCount":4,"participants":["Alexander Kuleshov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"255004","messageId":"1421867004-31672-1-git-send-email-kuleshovmail@gmail.com","threadId":"38421","inReplyTo":null,"subject":"[PATCH] git-add--interactive: print message if there are no untracked files","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-21T19:03:24Z","receivedAt":"2015-01-21T19:03:24Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"If user selects 'add untracked' and there are no untracked files,\n\"Add untracked>>\" opens. But it does not make sense in this case, because there\nare no untracked files. So let's print message and exit from \"add untracked\" mode.\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n git-add--interactive.perl | 14 +++++++++-----\n 1 file changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 94b988c..1a6dcf3 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -724,11 +724,15 @@ sub revert_cmd {\n }\n \n sub add_untracked_cmd {\n-\tmy @add = list_and_choose({ PROMPT => 'Add untracked' },\n-\t\t\t\t  list_untracked());\n-\tif (@add) {\n-\t\tsystem(qw(git update-index --add --), @add);\n-\t\tsay_n_paths('added', @add);\n+\tif (system(qw(git ls-files --others --exclude-standard --))) {\n+\t\tmy @add = list_and_choose({ PROMPT => 'Add untracked' },\n+\t\t\t\t\t  list_untracked());\n+\t\tif (@add) {\n+\t\t\tsystem(qw(git update-index --add --), @add);\n+\t\t\tsay_n_paths('added', @add);\n+\t\t}\n+\t} else {\n+\t\tprint \"No untracked files.\\n\";\n \t}\n \tprint \"\\n\";\n }\n-- \n2.3.0.rc1.247.gb53aa6f\n"},{"id":"255030","messageId":"xmqqmw5bx2ii.fsf@gitster.dls.corp.google.com","threadId":"38421","inReplyTo":"1421867004-31672-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] git-add--interactive: print message if there are no untracked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-21T21:11:33Z","receivedAt":"2015-01-21T21:11:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Kuleshov <kuleshovmail@gmail.com> writes:\n\n> If user selects 'add untracked' and there are no untracked files,\n> \"Add untracked>>\" opens. But it does not make sense in this case,\n> because there are no untracked files. So let's print message and\n> exit from \"add untracked\" mode.\n\nThat reasoning makes perfect sense.\n\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  git-add--interactive.perl | 14 +++++++++-----\n>  1 file changed, 9 insertions(+), 5 deletions(-)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 94b988c..1a6dcf3 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -724,11 +724,15 @@ sub revert_cmd {\n>  }\n>  \n>  sub add_untracked_cmd {\n> -\tmy @add = list_and_choose({ PROMPT => 'Add untracked' },\n> -\t\t\t\t  list_untracked());\n> -\tif (@add) {\n> -\t\tsystem(qw(git update-index --add --), @add);\n> -\t\tsay_n_paths('added', @add);\n> +\tif (system(qw(git ls-files --others --exclude-standard --))) {\n\nBut this ls-files invocation that knows too much about how\nlist_untracked() computes things does not.\n\nWhy not\n\n\tmy @add = list_untracked();\n        if (@add) {\n        \t@add = list_and_choose({...}, @add);\n\t}\n        if (!@add) {\n\t\tNothing to do;\n\t} else {\n\t\tRun update-index\n\t}\n\nor something instead?\n\n> +\t\tmy @add = list_and_choose({ PROMPT => 'Add untracked' },\n> +\t\t\t\t\t  list_untracked());\n> +\t\tif (@add) {\n> +\t\t\tsystem(qw(git update-index --add --), @add);\n> +\t\t\tsay_n_paths('added', @add);\n> +\t\t}\n> +\t} else {\n> +\t\tprint \"No untracked files.\\n\";\n>  \t}\n>  \tprint \"\\n\";\n>  }\n"},{"id":"255032","messageId":"xmqqegqnx281.fsf@gitster.dls.corp.google.com","threadId":"38421","inReplyTo":"xmqqmw5bx2ii.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-add--interactive: print message if there are no untracked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-21T21:17:50Z","receivedAt":"2015-01-21T21:17:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>>  sub add_untracked_cmd {\n>> -\tmy @add = list_and_choose({ PROMPT => 'Add untracked' },\n>> -\t\t\t\t  list_untracked());\n>> -\tif (@add) {\n>> -\t\tsystem(qw(git update-index --add --), @add);\n>> -\t\tsay_n_paths('added', @add);\n>> +\tif (system(qw(git ls-files --others --exclude-standard --))) {\n>\n> But this ls-files invocation that knows too much about how\n> list_untracked() computes things does not.\n>\n> Why not\n> ...\n> or something instead?\n\nActually, is there any case where list_and_choose() should give a\nprompt to choose from zero candidates?\n\nIn other words, I am wondering if this affects other callers of\nlist_and_choose in any negative way.\n\n git-add--interactive.perl | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 94b988c..46ed9a7 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -519,6 +519,10 @@ sub error_msg {\n sub list_and_choose {\n \tmy ($opts, @stuff) = @_;\n \tmy (@chosen, @return);\n+\n+\tif (!@stuff) {\n+\t\treturn @return;\n+\t}\n \tmy $i;\n \tmy @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY};\n \n"},{"id":"255065","messageId":"CANCZXo5OQHNCyz3kUY6c0Y_Lpabee0WS+eQ5G53QupMLwOw=jg@mail.gmail.com","threadId":"38421","inReplyTo":"xmqqegqnx281.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-add--interactive: print message if there are no untracked files","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-22T07:11:37Z","receivedAt":"2015-01-22T07:11:37Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"No i don't see any reasons why list_and_choose() shoud give a prompt\nwithout candidates. Will resed patch.\n\nThank you.\n\n2015-01-22 3:17 GMT+06:00 Junio C Hamano <gitster@pobox.com>:\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>>>  sub add_untracked_cmd {\n>>> -    my @add = list_and_choose({ PROMPT => 'Add untracked' },\n>>> -                              list_untracked());\n>>> -    if (@add) {\n>>> -            system(qw(git update-index --add --), @add);\n>>> -            say_n_paths('added', @add);\n>>> +    if (system(qw(git ls-files --others --exclude-standard --))) {\n>>\n>> But this ls-files invocation that knows too much about how\n>> list_untracked() computes things does not.\n>>\n>> Why not\n>> ...\n>> or something instead?\n>\n> Actually, is there any case where list_and_choose() should give a\n> prompt to choose from zero candidates?\n>\n> In other words, I am wondering if this affects other callers of\n> list_and_choose in any negative way.\n>\n>  git-add--interactive.perl | 4 ++++\n>  1 file changed, 4 insertions(+)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 94b988c..46ed9a7 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -519,6 +519,10 @@ sub error_msg {\n>  sub list_and_choose {\n>         my ($opts, @stuff) = @_;\n>         my (@chosen, @return);\n> +\n> +       if (!@stuff) {\n> +               return @return;\n> +       }\n>         my $i;\n>         my @prefixes = find_unique_prefixes(@stuff) unless $opts->{LIST_ONLY};\n>\n\n\n\n-- \n_________________________\n0xAX\n"}]}