# git rm --pathspec-from-file does not work in subdirectories

4 messages from 2021-05-28 to 2021-05-28. Participants: Dietrich Epp, Junio C Hamano, Eric Sunshine.
Thread: https://gitlist.dev/t/55787

## Dietrich Epp, 2021-05-28 04:20

Subject: git rm --pathspec-from-file does not work in subdirectories
Message-ID: <CAKGua8U25GF=mC+vRARRY99ZgaHoUOA7vppmOUdWoeB=bf3NAA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKGua8U25GF%3DmC%2BvRARRY99ZgaHoUOA7vppmOUdWoeB%3Dbf3NAA%40mail.gmail.com

```
How to reproduce: cd into a subdirectory and use git rm
--pathspec-from-file. For example, in Git's repo, at the top level:

$ git rm --pathspec-from-file=/dev/null
fatal: No pathspec was given. Which files should I remove?
$ cd compat
$ git rm --pathspec-from-file=/dev/null
fatal: --pathspec-from-file is incompatible with pathspec arguments

However, git add works as expected.

Tested on commit 5afd72a96f0a3f65a832fd1448d9de1c534aaa69 (master)

```

## Junio C Hamano, 2021-05-28 04:59

Subject: Re: git rm --pathspec-from-file does not work in subdirectories
Message-ID: <xmqqlf7z78sb.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqlf7z78sb.fsf%40gitster.g
In-Reply-To: <CAKGua8U25GF=mC+vRARRY99ZgaHoUOA7vppmOUdWoeB=bf3NAA@mail.gmail.com>

```
Dietrich Epp <depp@moria.us> writes:

> How to reproduce: cd into a subdirectory and use git rm
> --pathspec-from-file. For example, in Git's repo, at the top level:
>
> $ git rm --pathspec-from-file=/dev/null
> fatal: No pathspec was given. Which files should I remove?
> $ cd compat
> $ git rm --pathspec-from-file=/dev/null
> fatal: --pathspec-from-file is incompatible with pathspec arguments

Thanks for a report.

I think this reveals issues with not just the --pathspec-from-file
which has been added relatively recently, but potentially a larger
issue "git rm" from subdirectory has.

When run from a subdirectory, "git rm" without pathspec behaves
as if a single "." (i.e. everything underneath the current
directory) is given as the pathspec.  Of course, this is incompatible
with reading of the pathspec elements from a file and unfortunately
it cannot be disabled, so there currently is no way to use the option
if you are in a subdirectory.

But a potentially larger problem is that "git rm -r" will remove
everything under the current directory unless you are at the top
level of the working tree, even when the user does not give "." to
explicitly say "I want everything under the current directory gone".

I wonder if the attached patch would make both issues better.


```

## Eric Sunshine, 2021-05-28 05:08

Subject: Re: git rm --pathspec-from-file does not work in subdirectories
Message-ID: <CAPig+cT6ztfUYjbsfFmYZ=UOcyk=9rFKqEuE=EE4y2rdBftGag@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcT6ztfUYjbsfFmYZ%3DUOcyk%3D9rFKqEuE%3DEE4y2rdBftGag%40mail.gmail.com
In-Reply-To: <xmqqlf7z78sb.fsf@gitster.g>

```
On Fri, May 28, 2021 at 1:07 AM Junio C Hamano <gitster@pobox.com> wrote:
> I wonder if the attached patch would make both issues better.

The "attached patch" is missing.

```

## Junio C Hamano, 2021-05-28 05:56

Subject: Re: git rm --pathspec-from-file does not work in subdirectories
Message-ID: <xmqqh7in7650.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqh7in7650.fsf%40gitster.g
In-Reply-To: <CAPig+cT6ztfUYjbsfFmYZ=UOcyk=9rFKqEuE=EE4y2rdBftGag@mail.gmail.com>

```
Eric Sunshine <sunshine@sunshineco.com> writes:

> On Fri, May 28, 2021 at 1:07 AM Junio C Hamano <gitster@pobox.com> wrote:
>> I wonder if the attached patch would make both issues better.
>
> The "attached patch" is missing.

Heh.  Something along this line, but I think pathspec-from-file
still needs a bit more work even with this patch.

 builtin/rm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git c/builtin/rm.c w/builtin/rm.c
index 8a24c715e0..a4a8a1ad8d 100644
--- c/builtin/rm.c
+++ w/builtin/rm.c
@@ -265,7 +265,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 			     builtin_rm_usage, 0);
 
 	parse_pathspec(&pathspec, 0,
-		       PATHSPEC_PREFER_CWD,
+		       PATHSPEC_PREFER_FULL,
 		       prefix, argv);
 
 	if (pathspec_from_file) {
@@ -273,7 +273,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 			die(_("--pathspec-from-file is incompatible with pathspec arguments"));
 
 		parse_pathspec_file(&pathspec, 0,
-				    PATHSPEC_PREFER_CWD,
+				    PATHSPEC_PREFER_FULL,
 				    prefix, pathspec_from_file, pathspec_file_nul);
 	} else if (pathspec_file_nul) {
 		die(_("--pathspec-file-nul requires --pathspec-from-file"));

```
