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

6 messages from 2011-04-19 to 2011-04-20. Participants: Junio C Hamano, Sverre Rabbelier, Jeff King, Michael J Gruber.
Thread: https://gitlist.dev/t/27136

## Junio C Hamano, 2011-04-19 19:18

Subject: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <7v1v0y59tv.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1v0y59tv.fsf%40alter.siamese.dyndns.org

```
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(-)

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, 2011-04-19 19:46

Subject: Re: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <BANLkTin4iVLzga6gFAh+x8nRTKuVTTFPqA@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTin4iVLzga6gFAh%2Bx8nRTKuVTTFPqA%40mail.gmail.com
In-Reply-To: <7v1v0y59tv.fsf@alter.siamese.dyndns.org>

```
Heya,

On Tue, Apr 19, 2011 at 21:18, Junio C Hamano <gitster@pobox.com> wrote:
>  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, 2011-04-19 21:41

Subject: Re: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <7voc41537g.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7voc41537g.fsf%40alter.siamese.dyndns.org
In-Reply-To: <BANLkTin4iVLzga6gFAh+x8nRTKuVTTFPqA@mail.gmail.com>

```
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, 2011-04-19 21:47

Subject: Re: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <BANLkTimKL2bbmOdh35FDZwf2uAzO=nJkFQ@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTimKL2bbmOdh35FDZwf2uAzO%3DnJkFQ%40mail.gmail.com
In-Reply-To: <7voc41537g.fsf@alter.siamese.dyndns.org>

```
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, 2011-04-20 05:57

Subject: Re: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <20110420055758.GC28597@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110420055758.GC28597%40sigill.intra.peff.net
In-Reply-To: <7v1v0y59tv.fsf@alter.siamese.dyndns.org>

```
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

```

## Michael J Gruber, 2011-04-20 08:18

Subject: Re: [RFC/PATCH] git add: notice removal of tracked paths by default
Message-ID: <4DAE96C7.9070904@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4DAE96C7.9070904%40drmicha.warpmail.net
In-Reply-To: <20110420055758.GC28597@sigill.intra.peff.net>

```
Jeff King venit, vidit, dixit 20.04.2011 07:57:
> 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

```
