git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 19, 2011, 19:18 UTC
Message-ID
<7v1v0y59tv.fsf@alter.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
Next: Sverre Rabbelier
Message 1 of 6 in “git add: notice removal of tracked paths by default”
  1. git add: notice removal of tracked paths by defaultJunio C Hamano, Apr 19, 2011
  2. Sverre RabbelierApr 19, 2011
  3. Junio C HamanoApr 19, 2011
  4. Sverre RabbelierApr 19, 2011
  5. Jeff KingApr 20, 2011
  6. Michael J GruberApr 20, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.