{"thread":{"id":"42695","subject":"[PATCH] pathspec: warn on empty strings as pathspec","startedAt":"2016-06-22T23:00:42Z","lastAt":"2016-06-24T18:22:32Z","messageCount":5,"participants":["Emily Xie","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"289934","messageId":"20160622230024.24034-1-emilyxxie@gmail.com","threadId":"42695","inReplyTo":null,"subject":"[PATCH] pathspec: warn on empty strings as pathspec","fromName":"Emily Xie","fromEmail":"emilyxxie@gmail.com","sentAt":"2016-06-22T23:00:24Z","receivedAt":"2016-06-22T23:00:42Z","isPatch":true,"sender":{"key":"emilyxxie@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5360525?v=4"},"body":"Currently, passing an empty string as a pathspec results in\na match on all paths. This is because a pathspec match is a\nleading substring match that honors directory boundaries.\nSo, just as pathspec \"dir/\" (or \"dir\") matches \"dir/file\",\n\"\" matches \"file\".\n\nHowever, this causes problems. Namely, a user's\ncarelessly-written script could accidentally assign an\nempty string to a variable that then gets passed to a Git\ncommand invocation, e.g.:\n\n        git rm -r \"$path\"\n        git add \"$path\"\n\nwhich would unintentionally affect all paths in the current\ndirectory.\n\nThe fix for this issue requires a two-step approach. As\nthere may be existing scripts that knowingly use empty\nstrings in this manner, the first step simply invokes a\nwarning that (1) declares using empty strings to\nmatch all paths will become invalid and (2) asks the user\nto use \".\" if their intent was to match all.\n\nFor step two, a follow-up patch several release cycles\nlater will remove the warnings and throw an error instead.\n\nThis patch is the first step.\n\nSigned-off-by: Emily Xie <emilyxxie@gmail.com>\nReported-by: David Turner <novalis@novalis.org>\nMentored-by: Michail Denchev <mdenchev@gmail.com>\nThanks-to: Sarah Sharp <sarah@thesharps.us> and James Sharp <jamey@minilop.net>\n---\n pathspec.c     | 11 +++++++++--\n t/t3600-rm.sh  |  5 +++++\n t/t3700-add.sh |  5 +++++\n 3 files changed, 19 insertions(+), 2 deletions(-)\n\ndiff --git a/pathspec.c b/pathspec.c\nindex c9e9b6c..02aa691 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -364,7 +364,7 @@ void parse_pathspec(struct pathspec *pathspec,\n {\n \tstruct pathspec_item *item;\n \tconst char *entry = argv ? *argv : NULL;\n-\tint i, n, prefixlen, nr_exclude = 0;\n+\tint i, n, prefixlen, warn_empty_string, nr_exclude = 0;\n \n \tmemset(pathspec, 0, sizeof(*pathspec));\n \n@@ -402,8 +402,15 @@ void parse_pathspec(struct pathspec *pathspec,\n \t}\n \n \tn = 0;\n-\twhile (argv[n])\n+\twarn_empty_string = 1;\n+\twhile (argv[n]) {\n+\t\tif (*argv[n] == '\\0' && warn_empty_string) {\n+\t\t\twarning(_(\"empty strings as pathspecs will be made invalid in upcoming releases. \"\n+\t\t\t          \"please use . instead if you meant to match all paths\"));\n+\t\t\twarn_empty_string = 0;\n+\t\t}\n \t\tn++;\n+\t}\n \n \tpathspec->nr = n;\n \tALLOC_ARRAY(pathspec->items, n);\ndiff --git a/t/t3600-rm.sh b/t/t3600-rm.sh\nindex d046d98..14f0edc 100755\n--- a/t/t3600-rm.sh\n+++ b/t/t3600-rm.sh\n@@ -881,4 +881,9 @@ test_expect_success 'rm files with two different errors' '\n \ttest_i18ncmp expect actual\n '\n \n+test_expect_success 'rm empty string should invoke warning' '\n+\tgit rm -rf \"\" 2>output &&\n+\ttest_i18ngrep \"warning: empty strings\" output\n+'\n+\n test_done\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex f14a665..05379d0 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -332,4 +332,9 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out\n \ttest_i18ncmp expect.err actual.err\n '\n \n+test_expect_success 'git add empty string should invoke warning' '\n+\tgit add \"\" 2>output &&\n+\ttest_i18ngrep \"warning: empty strings\" output\n+'\n+\n test_done\n-- \n2.8.4\n\n"},{"id":"289937","messageId":"xmqqmvmckebv.fsf@gitster.mtv.corp.google.com","threadId":"42695","inReplyTo":"20160622230024.24034-1-emilyxxie@gmail.com","subject":"Re: [PATCH] pathspec: warn on empty strings as pathspec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-22T23:12:52Z","receivedAt":"2016-06-22T23:13:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Emily Xie <emilyxxie@gmail.com> writes:\n\n> The fix for this issue requires a two-step approach. As\n> there may be existing scripts that knowingly use empty\n> strings in this manner, the first step simply invokes a\n> warning that (1) declares using empty strings to\n> match all paths will become invalid and (2) asks the user\n> to use \".\" if their intent was to match all.\n>\n> For step two, a follow-up patch several release cycles\n> later will remove the warnings and throw an error instead.\n>\n> This patch is the first step.\n>\n> Signed-off-by: Emily Xie <emilyxxie@gmail.com>\n> Reported-by: David Turner <novalis@novalis.org>\n> Mentored-by: Michail Denchev <mdenchev@gmail.com>\n> Thanks-to: Sarah Sharp <sarah@thesharps.us> and James Sharp <jamey@minilop.net>\n> ---\n\nLooks sensible.  I personally do not think warn-only-once matters in\npractice, but now you have implemented it, it is an additional nice\ntouch ;-)\n\nWill queue.\n\nThanks.\n"},{"id":"289938","messageId":"CAAin2AQR3yP7X=NLQ=9+0QGJZMCN7=xbpZ=H7r56RvvBfLJSEg@mail.gmail.com","threadId":"42695","inReplyTo":"xmqqmvmckebv.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] pathspec: warn on empty strings as pathspec","fromName":"Emily Xie","fromEmail":"emilyxxie@gmail.com","sentAt":"2016-06-22T23:48:47Z","receivedAt":"2016-06-22T23:49:30Z","isPatch":true,"sender":{"key":"emilyxxie@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5360525?v=4"},"body":"Awesome. Thanks, Junio---this is exciting!\n\nAs for step 2: do you have a good sense on the timing? Around how long\nshould I wait to submit the patch for it?\n\nOtherwise, let me know if there is anything else that I need to do!\n\n- Emily\n"},{"id":"289941","messageId":"xmqqh9ckjuon.fsf@gitster.mtv.corp.google.com","threadId":"42695","inReplyTo":"CAAin2AQR3yP7X=NLQ=9+0QGJZMCN7=xbpZ=H7r56RvvBfLJSEg@mail.gmail.com","subject":"Re: [PATCH] pathspec: warn on empty strings as pathspec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-23T06:17:12Z","receivedAt":"2016-06-23T06:17:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Emily Xie <emilyxxie@gmail.com> writes:\n\n> Awesome. Thanks, Junio---this is exciting!\n\nNo, thank _you_.\n\n> As for step 2: do you have a good sense on the timing? Around how long\n> should I wait to submit the patch for it?\n\nNot so fast.  We'll wait for others to comment first.\n\nI am queuing this change but that does not mean anything more than\nthat I am not outright rejecting the idea.\n\nIt is possible that others may assess the cost of having to do the\ntwo-step migration differently, and the list concensus may end up\nbeing \"if it hurts, don't pass an empty string\", i.e. we'd better\nwithout this patch or subsequent second step.  If that happens, the\nfirst step dies without hitting 'next'.  I'd say we'd wait at least\nfor a week.\n\nOtherwise, if the change is received favourably, we'll merge it to\n'next', do the same waiting for comments.  Repeat the same and then\nmerge to 'master'.  After it hits the next feature release (probably\nat around the end of August), the change will be seen by wider\ngeneral public, and at that point we may see strong opposition from\nthem with a good argument neither of us thought of why we shouldn't\ndo this change, in which case we might have to revise the plan and\nscrap the whole thing.\n\nSo, we'll wait and see.\n\n"},{"id":"290038","messageId":"CAAin2ASggO1ZUqT_nfokkYL40vSDSdPtAVq4H2Z9A7K633xq3Q@mail.gmail.com","threadId":"42695","inReplyTo":"xmqqh9ckjuon.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] pathspec: warn on empty strings as pathspec","fromName":"Emily Xie","fromEmail":"emilyxxie@gmail.com","sentAt":"2016-06-24T18:21:43Z","receivedAt":"2016-06-24T18:22:32Z","isPatch":true,"sender":{"key":"emilyxxie@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5360525?v=4"},"body":"I suppose I got ahead of myself there. :-) Thanks for the\nclarification on the process.\n\nOn Thu, Jun 23, 2016 at 2:17 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Emily Xie <emilyxxie@gmail.com> writes:\n>\n>> Awesome. Thanks, Junio---this is exciting!\n>\n> No, thank _you_.\n>\n>> As for step 2: do you have a good sense on the timing? Around how long\n>> should I wait to submit the patch for it?\n>\n> Not so fast.  We'll wait for others to comment first.\n>\n> I am queuing this change but that does not mean anything more than\n> that I am not outright rejecting the idea.\n>\n> It is possible that others may assess the cost of having to do the\n> two-step migration differently, and the list concensus may end up\n> being \"if it hurts, don't pass an empty string\", i.e. we'd better\n> without this patch or subsequent second step.  If that happens, the\n> first step dies without hitting 'next'.  I'd say we'd wait at least\n> for a week.\n>\n> Otherwise, if the change is received favourably, we'll merge it to\n> 'next', do the same waiting for comments.  Repeat the same and then\n> merge to 'master'.  After it hits the next feature release (probably\n> at around the end of August), the change will be seen by wider\n> general public, and at that point we may see strong opposition from\n> them with a good argument neither of us thought of why we shouldn't\n> do this change, in which case we might have to revise the plan and\n> scrap the whole thing.\n>\n> So, we'll wait and see.\n>\n\n\n\n-- \nEmily Xie\nxie-emily.com\n207.399.6370\n"}]}