git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Minor UX annoyance w/`git add --patch untracked/file`
@ 2023-11-30 19:26 Vito Caputo
  2023-12-06 19:54 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Vito Caputo @ 2023-11-30 19:26 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Minor UX annoyance w/`git add --patch untracked/file`
  2023-11-30 19:26 Minor UX annoyance w/`git add --patch untracked/file` Vito Caputo
@ 2023-12-06 19:54 ` Jeff King
  2023-12-08 21:09   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2023-12-06 19:54 UTC (permalink / raw)
  To: Vito Caputo; +Cc: git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Minor UX annoyance w/`git add --patch untracked/file`
  2023-12-06 19:54 ` Jeff King
@ 2023-12-08 21:09   ` Junio C Hamano
  2023-12-08 22:29     ` Taylor Blau
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2023-12-08 21:09 UTC (permalink / raw)
  To: Jeff King; +Cc: Vito Caputo, git

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Minor UX annoyance w/`git add --patch untracked/file`
  2023-12-08 21:09   ` Junio C Hamano
@ 2023-12-08 22:29     ` Taylor Blau
  0 siblings, 0 replies; 4+ messages in thread
From: Taylor Blau @ 2023-12-08 22:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Vito Caputo, git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-08 22:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-30 19:26 Minor UX annoyance w/`git add --patch untracked/file` Vito Caputo
2023-12-06 19:54 ` Jeff King
2023-12-08 21:09   ` Junio C Hamano
2023-12-08 22:29     ` Taylor Blau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).