# Minor UX annoyance w/`git add --patch untracked/file`

4 messages from 2023-11-30 to 2023-12-08. Participants: Vito Caputo, Jeff King, Junio C Hamano, Taylor Blau.
Thread: https://gitlist.dev/t/60573

## Vito Caputo, 2023-11-30 19:26

Subject: Minor UX annoyance w/`git add --patch untracked/file`
Message-ID: <20231130192637.wqpmidfv2roqmxdx@shells.gnugeneration.com>
URL: https://gitlist.dev/e/20231130192637.wqpmidfv2roqmxdx%40shells.gnugeneration.com

```
Hello list,

Couldn't the following two steps be done automagically by --patch:

ˋˋˋ
git add -N path/to/untracked/file/wishing/to/partially/add
git add --patch path/to/untracked/file/wishing/to/partially/add
ˋˋˋ

when one simply does:

`git add --patch path/to/untracked/file/wishing/to/partially/add`

?

Cheers,
Vito Caputo

```

## Jeff King, 2023-12-06 19:54

Subject: Re: Minor UX annoyance w/`git add --patch untracked/file`
Message-ID: <20231206195407.GD103708@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20231206195407.GD103708%40coredump.intra.peff.net
In-Reply-To: <20231130192637.wqpmidfv2roqmxdx@shells.gnugeneration.com>

```
On Thu, Nov 30, 2023 at 11:26:37AM -0800, Vito Caputo wrote:

> Couldn't the following two steps be done automagically by --patch:
> 
> ˋˋˋ
> git add -N path/to/untracked/file/wishing/to/partially/add
> git add --patch path/to/untracked/file/wishing/to/partially/add
> ˋˋˋ
> 
> when one simply does:
> 
> `git add --patch path/to/untracked/file/wishing/to/partially/add`
> 
> ?

They _could_, but keep in mind that the argument is not strictly a path.
It is a pathspec that may match multiple paths. So:

  git add -p path/to/

for example will pick up the tracked files in path/to/, but not your
untracked one.

It would be possible to distinguish the two cases, and only auto-add
files which are explicitly mentioned as full paths. But we usually shy
away from too many special cases like this, as the resulting behavior
can end up confusing and hard to explain.

-Peff

```

## Junio C Hamano, 2023-12-08 21:09

Subject: Re: Minor UX annoyance w/`git add --patch untracked/file`
Message-ID: <xmqqmsuk1jvp.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqmsuk1jvp.fsf%40gitster.g
In-Reply-To: <20231206195407.GD103708@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> They _could_, but keep in mind that the argument is not strictly a path.
> It is a pathspec that may match multiple paths. So:
>
>   git add -p path/to/
>
> for example will pick up the tracked files in path/to/, but not your
> untracked one.

The corresponding command w/o "-p", i.e., "git add path/to/", will
pick up both tracked and untracked ones from the named directory,
while honoring the ignore settings.  So I suspect it might feel more
natural if "-p" followed suit.

Not that I feel strongly either way.  The command has only worked
with already tracked files since its inception and nobody complained
in the past 15 years or so, probably because nobody cared that much
for relatively rare event of creating a new file and adding it.

Thanks.

```

## Taylor Blau, 2023-12-08 22:29

Subject: Re: Minor UX annoyance w/`git add --patch untracked/file`
Message-ID: <ZXOY1Qq4MKQPEEAZ@nand.local>
URL: https://gitlist.dev/e/ZXOY1Qq4MKQPEEAZ%40nand.local
In-Reply-To: <xmqqmsuk1jvp.fsf@gitster.g>

```
On Sat, Dec 09, 2023 at 06:09:46AM +0900, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > They _could_, but keep in mind that the argument is not strictly a path.
> > It is a pathspec that may match multiple paths. So:
> >
> >   git add -p path/to/
> >
> > for example will pick up the tracked files in path/to/, but not your
> > untracked one.
>
> The corresponding command w/o "-p", i.e., "git add path/to/", will
> pick up both tracked and untracked ones from the named directory,
> while honoring the ignore settings.  So I suspect it might feel more
> natural if "-p" followed suit.

I tend to agree. I do think that the full specification of when "git add
-p" implies "git add -N ... && git add -p" would be difficult to explain
to users.

But I think it's a worthwhile trade-off in that it makes the UX more
consistent in the common case (where the argument to add is a literal
path, not a pathspec).

Thanks,
Taylor

```
