{"thread":{"id":"55787","subject":"git rm --pathspec-from-file does not work in subdirectories","startedAt":"2021-05-28T04:24:17Z","lastAt":"2021-05-28T05:57:51Z","messageCount":4,"participants":["Dietrich Epp","Junio C Hamano","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"425733","messageId":"CAKGua8U25GF=mC+vRARRY99ZgaHoUOA7vppmOUdWoeB=bf3NAA@mail.gmail.com","threadId":"55787","inReplyTo":null,"subject":"git rm --pathspec-from-file does not work in subdirectories","fromName":"Dietrich Epp","fromEmail":"depp@moria.us","sentAt":"2021-05-28T04:20:47Z","receivedAt":"2021-05-28T04:24:17Z","isPatch":false,"sender":{"key":"depp@moria.us","avatar":null},"body":"How to reproduce: cd into a subdirectory and use git rm\n--pathspec-from-file. For example, in Git's repo, at the top level:\n\n$ git rm --pathspec-from-file=/dev/null\nfatal: No pathspec was given. Which files should I remove?\n$ cd compat\n$ git rm --pathspec-from-file=/dev/null\nfatal: --pathspec-from-file is incompatible with pathspec arguments\n\nHowever, git add works as expected.\n\nTested on commit 5afd72a96f0a3f65a832fd1448d9de1c534aaa69 (master)\n"},{"id":"425737","messageId":"xmqqlf7z78sb.fsf@gitster.g","threadId":"55787","inReplyTo":"CAKGua8U25GF=mC+vRARRY99ZgaHoUOA7vppmOUdWoeB=bf3NAA@mail.gmail.com","subject":"Re: git rm --pathspec-from-file does not work in subdirectories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-28T04:59:48Z","receivedAt":"2021-05-28T04:59:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dietrich Epp <depp@moria.us> writes:\n\n> How to reproduce: cd into a subdirectory and use git rm\n> --pathspec-from-file. For example, in Git's repo, at the top level:\n>\n> $ git rm --pathspec-from-file=/dev/null\n> fatal: No pathspec was given. Which files should I remove?\n> $ cd compat\n> $ git rm --pathspec-from-file=/dev/null\n> fatal: --pathspec-from-file is incompatible with pathspec arguments\n\nThanks for a report.\n\nI think this reveals issues with not just the --pathspec-from-file\nwhich has been added relatively recently, but potentially a larger\nissue \"git rm\" from subdirectory has.\n\nWhen run from a subdirectory, \"git rm\" without pathspec behaves\nas if a single \".\" (i.e. everything underneath the current\ndirectory) is given as the pathspec.  Of course, this is incompatible\nwith reading of the pathspec elements from a file and unfortunately\nit cannot be disabled, so there currently is no way to use the option\nif you are in a subdirectory.\n\nBut a potentially larger problem is that \"git rm -r\" will remove\neverything under the current directory unless you are at the top\nlevel of the working tree, even when the user does not give \".\" to\nexplicitly say \"I want everything under the current directory gone\".\n\nI wonder if the attached patch would make both issues better.\n\n"},{"id":"425738","messageId":"CAPig+cT6ztfUYjbsfFmYZ=UOcyk=9rFKqEuE=EE4y2rdBftGag@mail.gmail.com","threadId":"55787","inReplyTo":"xmqqlf7z78sb.fsf@gitster.g","subject":"Re: git rm --pathspec-from-file does not work in subdirectories","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2021-05-28T05:08:41Z","receivedAt":"2021-05-28T05:08:57Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, May 28, 2021 at 1:07 AM Junio C Hamano <gitster@pobox.com> wrote:\n> I wonder if the attached patch would make both issues better.\n\nThe \"attached patch\" is missing.\n"},{"id":"425741","messageId":"xmqqh7in7650.fsf@gitster.g","threadId":"55787","inReplyTo":"CAPig+cT6ztfUYjbsfFmYZ=UOcyk=9rFKqEuE=EE4y2rdBftGag@mail.gmail.com","subject":"Re: git rm --pathspec-from-file does not work in subdirectories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-28T05:56:59Z","receivedAt":"2021-05-28T05:57:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Fri, May 28, 2021 at 1:07 AM Junio C Hamano <gitster@pobox.com> wrote:\n>> I wonder if the attached patch would make both issues better.\n>\n> The \"attached patch\" is missing.\n\nHeh.  Something along this line, but I think pathspec-from-file\nstill needs a bit more work even with this patch.\n\n builtin/rm.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git c/builtin/rm.c w/builtin/rm.c\nindex 8a24c715e0..a4a8a1ad8d 100644\n--- c/builtin/rm.c\n+++ w/builtin/rm.c\n@@ -265,7 +265,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\t     builtin_rm_usage, 0);\n \n \tparse_pathspec(&pathspec, 0,\n-\t\t       PATHSPEC_PREFER_CWD,\n+\t\t       PATHSPEC_PREFER_FULL,\n \t\t       prefix, argv);\n \n \tif (pathspec_from_file) {\n@@ -273,7 +273,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"--pathspec-from-file is incompatible with pathspec arguments\"));\n \n \t\tparse_pathspec_file(&pathspec, 0,\n-\t\t\t\t    PATHSPEC_PREFER_CWD,\n+\t\t\t\t    PATHSPEC_PREFER_FULL,\n \t\t\t\t    prefix, pathspec_from_file, pathspec_file_nul);\n \t} else if (pathspec_file_nul) {\n \t\tdie(_(\"--pathspec-file-nul requires --pathspec-from-file\"));\n"}]}