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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---

 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]