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

[PATCH 2/2] add: respect add.updateroot config option

From
Jeff King <peff@peff.net>
Date
Mar 13, 2013, 04:10 UTC
Message-ID
<20130313041037.GB5378@sigill.intra.peff.net>
In-Reply-To
<20130313040845.GA5057@sigill.intra.peff.net>

The `git add -u` command operates on the current subdir of the repository, but is transitioning to operate on the whole repository (see commit 0fa2eb5 for details). During the transition period, we issue a warning. For users who have read and accepted the warning, there is no way to jump directly to the future behavior and silence the warning. The config option added by this patch gives them such an option.

Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/config.txt | 19 +++++++++++++++++++
 builtin/add.c            | 10 ++++++++--
 t/t2200-add-update.sh    | 14 ++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index bbba728..be0f6fc 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -657,6 +657,25 @@ add.ignoreErrors::
 	convention for configuration variables.  Newer versions of Git
 	honor `add.ignoreErrors` as well.
 
+add.updateroot::
+	Historically, when the `git add -u` and `git add -A` commands
+	are run from a subdirectory of the repository and are not given
+	any pathspec, they have operated only on the subdirectory from
+	which they were called. In a future version of git, this behavior
+	will be switched to operate on the full repository instead. In
+	the meantime, issuing `git add -u` (or `-A`) from a subdirectory
+	continues to work on the subdirectory, but will now issue a
+	warning. If you are ready to move to the new behavior now,
+	accepting that you may be breaking existing scripts which expect
+	the old behavior, you can do so by setting `add.updateroot` to
+	`true`.
++
+Note that this is meant to let early adopters move to the new behavior
+immediately; it is not a toggle switch that will work forever.  After
+git transitions to the new behavior, this option will become a no-op;
+`git add -u` will always update the whole tree, and `git add -u .` will
+remain the correct way to limit to the current directory.
+
 alias.*::
 	Command aliases for the linkgit:git[1] command wrapper - e.g.
 	after defining "alias.last = cat-file commit HEAD", the invocation
diff --git a/builtin/add.c b/builtin/add.c
index ab1c9e8..95fe35e 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -22,6 +22,7 @@ static int take_worktree_changes;
 };
 static int patch_interactive, add_interactive, edit_interactive;
 static int take_worktree_changes;
+static int update_root;
 
 struct update_callback_data {
 	int flags;
@@ -297,6 +298,10 @@ static int add_config(const char *var, const char *value, void *cb)
 		ignore_add_errors = git_config_bool(var, value);
 		return 0;
 	}
+	if (!strcmp(var, "add.updateroot")) {
+		update_root = git_config_bool(var, value);
+		return 0;
+	}
 	return git_default_config(var, value, cb);
 }
 
@@ -390,12 +395,13 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		short_option_with_implicit_dot = "-u";
 	}
 	if (option_with_implicit_dot && !argc) {
+		static const char *root[2] = { ":/", NULL };
 		static const char *here[2] = { ".", NULL };
-		if (prefix)
+		if (!update_root && prefix)
 			warn_pathless_add(option_with_implicit_dot,
 					  short_option_with_implicit_dot);
 		argc = 1;
-		argv = here;
+		argv = update_root ? root : here;
 	}
 
 	add_new_files = !take_worktree_changes && !refresh_only;
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index fe4f548..b9215d3 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -91,6 +91,20 @@ test_expect_success 'update did not touch files at root' '
 	test_cmp expect actual
 '
 
+test_expect_success 'update with add.updateroot set' '
+	(
+		cd dir1 &&
+		echo more >>sub2 &&
+		git -c add.updateroot=true add -u
+	)
+'
+
+test_expect_success 'all paths are updated' '
+	>expect &&
+	git diff-files --name-status >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success SYMLINKS 'replace a file with a symlink' '
 
 	rm foo &&
-- 
1.8.2.rc2.7.gef06216
Previous: Jeff KingNext: Matthieu Moy
Message 19 of 51 in “"git add -u/-A" from future”
  1. 0/2 "git add -u/-A" from futureJunio C Hamano, Mar 8, 2013
  2. 1/2 require pathspec for "git add -u/-A"Junio C Hamano, Mar 8, 2013
  3. Matthieu MoyMar 10, 2013
  4. Junio C HamanoMar 11, 2013
  5. Matthieu MoyMar 11, 2013
  6. 1/2 add: update pathless 'add [-u|-A]' warning to reflect change of planMatthieu Moy, Mar 11, 2013
  7. 2/2 add: add a newline at the end of pathless 'add [-u|-A]' warningMatthieu Moy, Mar 11, 2013
  8. Junio C HamanoMar 11, 2013
  9. Matthieu MoyApr 2, 2013
  10. Junio C HamanoApr 2, 2013
  11. Matthieu MoyApr 2, 2013
  12. Jeff KingMar 12, 2013
  13. Matthieu MoyMar 12, 2013
  14. Jeff KingMar 13, 2013
  15. 1/2 t2200: check that "add -u" limits itself to subdirectoryJeff King, Mar 13, 2013
  16. Matthieu MoyMar 13, 2013
  17. Junio C HamanoMar 13, 2013
  18. Jeff KingMar 14, 2013
  19. 2/2 add: respect add.updateroot config optionJeff King, Mar 13, 2013
  20. Matthieu MoyMar 13, 2013
  21. Jeff KingMar 13, 2013
  22. Junio C HamanoMar 13, 2013
  23. Matthieu MoyMar 14, 2013
  24. 0/4 make pathless 'add [-u|-A]' warning less noisyJonathan Nieder, Mar 19, 2013
  25. 1/4 add: make pathless 'add [-u|-A]' warning a file-global functionJonathan Nieder, Mar 19, 2013
  26. 2/4 add: make warn_pathless_add() a no-op after first callJonathan Nieder, Mar 19, 2013
  27. 3/4 add -u: only show pathless 'add -u' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  28. Junio C HamanoMar 19, 2013
  29. Jonathan NiederMar 19, 2013
  30. Junio C HamanoMar 19, 2013
  31. Jonathan NiederMar 19, 2013
  32. Duy NguyenMar 19, 2013
  33. Jonathan NiederMar 19, 2013
  34. Matthieu MoyMar 19, 2013
  35. Junio C HamanoMar 19, 2013
  36. Jonathan NiederMar 19, 2013
  37. Junio C HamanoMar 19, 2013
  38. Jonathan NiederMar 19, 2013
  39. 4/4 add -A: only show pathless 'add -A' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  40. Jeff KingMar 19, 2013
  41. 2/2 git add: -u/-A now affects the entire working treeJunio C Hamano, Mar 8, 2013
  42. 0/6 make pathless 'add [-u|-A]' warning less noisyJonathan Nieder, Mar 19, 2013
  43. 1/6 t2200: check that "add -u" limits itself to subdirectoryJonathan Nieder, Mar 19, 2013
  44. 2/6 add: make pathless 'add [-u|-A]' warning a file-global functionJonathan Nieder, Mar 19, 2013
  45. 3/6 add: make warn_pathless_add() a no-op after first callJonathan Nieder, Mar 19, 2013
  46. 4/6 add -u: only show pathless 'add -u' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  47. Jeff KingMar 20, 2013
  48. Junio C HamanoMar 20, 2013
  49. 5/6 add -A: only show pathless 'add -A' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  50. Junio C HamanoMar 20, 2013
  51. 6/6 git add: -u/-A now affects the entire working treeJonathan Nieder, Mar 19, 2013

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.