git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH] git add: notice removal of tracked paths by default
@ 2011-04-19 19:18 Junio C Hamano
  2011-04-19 19:46 ` Sverre Rabbelier
  2011-04-20  5:57 ` Jeff King
  0 siblings, 2 replies; 6+ messages in thread
From: Junio C Hamano @ 2011-04-19 19:18 UTC (permalink / raw)
  To: git

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

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

* Re: [RFC/PATCH] git add: notice removal of tracked paths by default
  2011-04-19 19:18 [RFC/PATCH] git add: notice removal of tracked paths by default Junio C Hamano
@ 2011-04-19 19:46 ` Sverre Rabbelier
  2011-04-19 21:41   ` Junio C Hamano
  2011-04-20  5:57 ` Jeff King
  1 sibling, 1 reply; 6+ messages in thread
From: Sverre Rabbelier @ 2011-04-19 19:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

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

* Re: [RFC/PATCH] git add: notice removal of tracked paths by default
  2011-04-19 19:46 ` Sverre Rabbelier
@ 2011-04-19 21:41   ` Junio C Hamano
  2011-04-19 21:47     ` Sverre Rabbelier
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2011-04-19 21:41 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: git

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".

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

* Re: [RFC/PATCH] git add: notice removal of tracked paths by default
  2011-04-19 21:41   ` Junio C Hamano
@ 2011-04-19 21:47     ` Sverre Rabbelier
  0 siblings, 0 replies; 6+ messages in thread
From: Sverre Rabbelier @ 2011-04-19 21:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

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

* Re: [RFC/PATCH] git add: notice removal of tracked paths by default
  2011-04-19 19:18 [RFC/PATCH] git add: notice removal of tracked paths by default Junio C Hamano
  2011-04-19 19:46 ` Sverre Rabbelier
@ 2011-04-20  5:57 ` Jeff King
  2011-04-20  8:18   ` Michael J Gruber
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2011-04-20  5:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

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

* Re: [RFC/PATCH] git add: notice removal of tracked paths by default
  2011-04-20  5:57 ` Jeff King
@ 2011-04-20  8:18   ` Michael J Gruber
  0 siblings, 0 replies; 6+ messages in thread
From: Michael J Gruber @ 2011-04-20  8:18 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

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

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

end of thread, other threads:[~2011-04-20  8:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-19 19:18 [RFC/PATCH] git add: notice removal of tracked paths by default Junio C Hamano
2011-04-19 19:46 ` Sverre Rabbelier
2011-04-19 21:41   ` Junio C Hamano
2011-04-19 21:47     ` Sverre Rabbelier
2011-04-20  5:57 ` Jeff King
2011-04-20  8:18   ` Michael J Gruber

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).