threads / rfc / 27136

RFC patchgit add: notice removal of tracked paths by default

Subject: [RFC/PATCH] git add: notice removal of tracked paths by default

## tl;dr

6 messages between Apr 19, 2011 and Apr 20, 2011. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Junio C Hamano· Apr 19, 2011, 19:18 UTC · lore
When run without "-u" or "-A" option,
    $ edit subdir/x
    $ create subdir/y
    $ rm subdir/z
    $ git add subdir/

does not notice removal of paths (e.g. subdir/z) from the working tree. Make "git add" to pretend as if "-A" is given when there is a pathspec on the command line. "git add" without any argument continues to be a no-op.

When resolving a conflict to remove a path, the current code tells you to "git rm $path", but now with this patch you can say "git add $path". Of course you can do "git add -A $path" without this patch.

In either case, the operation "git add" is about "adding the state of the path in the working tree to the index". The state may happen to be "path removed", not "path has an updated content".

The semantic change can be seen by a breakage in t2200, test #15. There, a merge has conflicts in path4 (which is removed from the working tree), and test checks "git add path4" to resolve it must fail, and makes sure that the user must use "git rm path4" for that.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 This might not be such a good idea, and I do not have a strong opinion
 for this change, but merely a weatherbaloon.
 Having "git add ." notice removals might lead to mistakes ("oh, I only
 meant to record additions, and didn't want to record the removals"), but
 at the same time, leaving it not notice removals would lead to mistakes
 by the other people ("I added, removed and edited different paths, but
 why only removals are ignored?").
---
 builtin/add.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to builtin/add.c +3 −0
diff --git a/builtin/add.c b/builtin/add.c
index d39a6ab..0f534e3 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -386,6 +386,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
 	if (addremove && take_worktree_changes)
 		die(_("-A and -u are mutually incompatible"));
+	/* default "git add pathspec..." to "git add -A pathspec..." */
+	if (!take_worktree_changes && argc)
+		addremove = 1;
 	if (!show_only && ignore_missing)
 		die(_("Option --ignore-missing can only be used together with --dry-run"));
 	if ((addremove || take_worktree_changes) && !argc) {
-- 
1.7.5.rc3
Sverre Rabbelier· Apr 19, 2011, 19:46 UTC · re: Junio C Hamano · lore

Re: [RFC/PATCH] git add: notice removal of tracked paths by default

Heya,
On Tue, Apr 19, 2011 at 21:18, Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
>  Having "git add ." notice removals might lead to mistakes ("oh, I only
>  meant to record additions, and didn't want to record the removals"), but
>  at the same time, leaving it not notice removals would lead to mistakes
>  by the other people ("I added, removed and edited different paths, but
>  why only removals are ignored?").

Is there a way to add disable this somehow? I don't think we have a '--no-update', do we?

-- 
Cheers,

Sverre Rabbelier
Junio C Hamano· Apr 19, 2011, 21:41 UTC · re: Sverre Rabbelier · lore

Re: [RFC/PATCH] git add: notice removal of tracked paths by default

Sverre Rabbelier <srabbelier@gmail.com> writes:
> Is there a way to add disable this somehow? I don't think we have a
> '--no-update', do we?

If we need to be able to disable this, then we are probably better off not doing this change. After all, adding -A on the command line is easy.

The change makes sense only if nobody wants to do "only addition and modification".

I have a strong feeling that the current "git add $path" semantics came primarily from historical implementation and pure inertia, and not from a well thought out design. After all, when you are saying "git add ." (or "git add dir/"), you are saying that you want to take what you have in that directory as a whole, except for whatever is excluded with your well-maintained .gitignore file. It felt very unnatural that the command excluded removal without the "-A" option when I tried to be in that mindset.

But as I said, I do not have a strong opinion for this change, other than "if we need this optional, then it is not worth doing this".

Sverre Rabbelier· Apr 19, 2011, 21:47 UTC · re: Junio C Hamano · lore

Re: [RFC/PATCH] git add: notice removal of tracked paths by default

Heya,
On Tue, Apr 19, 2011 at 23:41, Junio C Hamano <gitster@pobox.com> wrote:
> But as I said, I do not have a strong opinion for this change, other than
> "if we need this optional, then it is not worth doing this".

Your argument makes sense, and I personally haven't run into a case where I _wouldn't_ want the suggested behavior, and I have run into cases several times where I _would've_ wanted the suggested behavior. So consider this a +1 for me on the idea.

-- 
Cheers,

Sverre Rabbelier
Jeff King· Apr 20, 2011, 05:57 UTC · re: Junio C Hamano · lore

Re: [RFC/PATCH] git add: notice removal of tracked paths by default

On Tue, Apr 19, 2011 at 12:18:20PM -0700, Junio C Hamano wrote:
> Make "git add" to pretend as if "-A" is given when there is a pathspec on
> the command line.  "git add" without any argument continues to be a no-op.

I like your proposed semantics much better. I remember many times early on with git cursing the current behavior, until I finally trained myself to do "git add -A".

Show 8 quoted lines
>  This might not be such a good idea, and I do not have a strong opinion
>  for this change, but merely a weatherbaloon.
> 
>  Having "git add ." notice removals might lead to mistakes ("oh, I only
>  meant to record additions, and didn't want to record the removals"), but
>  at the same time, leaving it not notice removals would lead to mistakes
>  by the other people ("I added, removed and edited different paths, but
>  why only removals are ignored?").

I suspect most people will want the new semantics, because no matter what your overall workflow, it is generally going to be some variant of:

  1. hack hack hack
  2. tell git about changes

And you don't really care about deletions versus modifications, you just want them all added. But you probably _do_ care about additions versus modififications, since step 1 often involves creating cruft that should remain untracked (whereas it very rarely involves _deleting_ precious files). And that's why we have "add -u", which should not go away.

My biggest worry would be people saying "eh? Add removes my files? That makes no sense!" But we more or less already have that with "add -u", and I think people have learned to accept that it is about "add the current state to the index" and not "add files to git".

-Peff
Michael J Gruber· Apr 20, 2011, 08:18 UTC · re: Jeff King · lore

Re: [RFC/PATCH] git add: notice removal of tracked paths by default

Jeff King venit, vidit, dixit 20.04.2011 07:57:
Show 36 quoted lines
> On Tue, Apr 19, 2011 at 12:18:20PM -0700, Junio C Hamano wrote:
> 
>> Make "git add" to pretend as if "-A" is given when there is a pathspec on
>> the command line.  "git add" without any argument continues to be a no-op.
> 
> I like your proposed semantics much better. I remember many times early
> on with git cursing the current behavior, until I finally trained myself
> to do "git add -A".
> 
>>  This might not be such a good idea, and I do not have a strong opinion
>>  for this change, but merely a weatherbaloon.
>>
>>  Having "git add ." notice removals might lead to mistakes ("oh, I only
>>  meant to record additions, and didn't want to record the removals"), but
>>  at the same time, leaving it not notice removals would lead to mistakes
>>  by the other people ("I added, removed and edited different paths, but
>>  why only removals are ignored?").
> 
> I suspect most people will want the new semantics, because no matter
> what your overall workflow, it is generally going to be some variant of:
> 
>   1. hack hack hack
>   2. tell git about changes
> 
> And you don't really care about deletions versus modifications, you just
> want them all added. But you probably _do_ care about additions versus
> modififications, since step 1 often involves creating cruft that should
> remain untracked (whereas it very rarely involves _deleting_ precious
> files). And that's why we have "add -u", which should not go away.
> 
> My biggest worry would be people saying "eh? Add removes my files? That
> makes no sense!" But we more or less already have that with "add -u",
> and I think people have learned to accept that it is about "add the
> current state to the index" and not "add files to git".
> 
> -Peff
Yes, that behaviour makes much more sense.

That means that "git add -A" is "git add ." and "-A" is not needed otherwise any more, right? makes sense, too, and we could probably deprecate (i.e. stop advertising) it.

Michael

← back to recent threads