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

[RFC/PATCH] add: warn when -u or -A is used without filepattern

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jan 21, 2013, 12:00 UTC
Message-ID
<1358769611-3625-1-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<7v1udfn0tm.fsf@alter.siamese.dyndns.org>

Most git commands that can be used with our without a filepattern are tree-wide by default, the filepattern being used to restrict their scope. A few exceptions are: 'git grep', 'git clean', 'git add -u' and 'git add -A'.

The inconsistancy of 'git add -u' and 'git add -A' are particularly problematic since other 'git add' subcommands (namely 'git add -p' and 'git add -e') are tree-wide by default.

Flipping the default now is unacceptable, so this patch starts training users to type explicitely 'git add -u|-A :/' or 'git add -u|-A .', to prepare for the next steps:

* forbid 'git add -u|-A' without filepattern (like 'git add' without
  option)
* much later, maybe, re-allow 'git add -u|-A' without filepattern, with a
  tree-wide scope.

A nice side effect of this patch is that it makes the :/ special filepattern easier to discover for users.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
Junio C Hamano <gitster@pobox.com> writes:
> The first step of "git add -u" migration plan would be to warn when
> no argument is given and update all the existing index entries, and
> give the same advise to use either "." or ":/".  Keep this for three
> cycles: 3 * (8 to 10 weeks per cycle) = 27 weeks ~ 1/2 year.

The first step should look like this patch. The message remains vague about the next steps ("change in a future Git version", no mention of the exact change nor of the exact version in which it will happen), but I'm fine with refining it (perhaps this could be a 2.0 change, like the change to push.default?).

 Documentation/git-add.txt |  7 ++++---
 builtin/add.c             | 30 +++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index fd9e36b..5333559 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -107,9 +107,10 @@ apply to the index. See EDITING PATCHES below.
 	from the index if the corresponding files in the working tree
 	have been removed.
 +
-If no <filepattern> is given, default to "."; in other words,
-update all tracked files in the current directory and its
-subdirectories.
+If no <filepattern> is given, the current version of Git defaults to
+"."; in other words, update all tracked files in the current directory
+and its subdirectories. This default will change in a future version
+of Git, hence the form without <filepattern> should not be used.
 
 -A::
 --all::
diff --git a/builtin/add.c b/builtin/add.c
index e664100..e6eb829 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -373,6 +373,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	int add_new_files;
 	int require_pathspec;
 	char *seen = NULL;
+	const char *option_with_implicit_dot = NULL;
 
 	git_config(add_config, NULL);
 
@@ -392,7 +393,34 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		die(_("-A and -u are mutually incompatible"));
 	if (!show_only && ignore_missing)
 		die(_("Option --ignore-missing can only be used together with --dry-run"));
-	if ((addremove || take_worktree_changes) && !argc) {
+	if (addremove)
+		option_with_implicit_dot = "--all";
+	if (take_worktree_changes)
+		option_with_implicit_dot = "--update";
+	if (option_with_implicit_dot && !argc) {
+		/*
+		 * To be consistant with "git add -p" and most Git
+		 * commands, we should default to being tree-wide, but
+		 * this is not the original behavior and can't be
+		 * changed until users trained themselves not to type
+		 * "git add -u" or "git add -A". For now, we warn and
+		 * keep the old behavior. Later, this warning can be
+		 * turned into a die(...), and eventually we may
+		 * reallow the command with a new behavior.
+		 */
+		warning(_("The behavior of 'git add %s' with no path argument will change in a future\n"
+			  "Git version and shouldn't be used anymore.  To add content for the whole tree, run:\n"
+			  "\n"
+			  "  git add %s :/\n"
+			  "\n"
+			  "To restrict the command to the current directory, run:\n"
+			  "\n"
+			  "  git add %s .\n"
+			  "\n"
+			  "With the current Git version, the command is restricted to the current directory."),
+			option_with_implicit_dot,
+			option_with_implicit_dot,
+			option_with_implicit_dot);
 		static const char *here[2] = { ".", NULL };
 		argc = 1;
 		argv = here;
-- 
1.8.0.319.g8abfee4
Previous: Piotr KrukowieckiNext: Robin Rosenberg
Message 27 of 53 in “[RFC] git rm -u”
  1. Eric James Michael RitzJan 19, 2013
  2. Tomas CarneckyJan 19, 2013
  3. Antoine PelisseJan 19, 2013
  4. Eric James Michael RitzJan 19, 2013
  5. Junio C HamanoFeb 25, 2013
  6. Antoine PelisseFeb 25, 2013
  7. Matthieu MoyFeb 25, 2013
  8. Antoine PelisseFeb 25, 2013
  9. Matthieu MoyFeb 25, 2013
  10. Junio C HamanoFeb 25, 2013
  11. Jonathan NiederJan 19, 2013
  12. Eric James Michael RitzJan 19, 2013
  13. Matthieu MoyJan 20, 2013
  14. Junio C HamanoJan 20, 2013
  15. Junio C HamanoJan 20, 2013
  16. Martin von ZweigbergkJan 20, 2013
  17. Matthieu MoyJan 21, 2013
  18. Junio C HamanoJan 20, 2013
  19. Eric James Michael RitzJan 20, 2013
  20. Piotr KrukowieckiJan 21, 2013
  21. Matthieu MoyJan 21, 2013
  22. Junio C HamanoJan 21, 2013
  23. Junio C HamanoJan 21, 2013
  24. Matthieu MoyJan 21, 2013
  25. Junio C HamanoJan 21, 2013
  26. Piotr KrukowieckiJan 21, 2013
  27. add: warn when -u or -A is used without filepatternMatthieu Moy, Jan 21, 2013
  28. Robin RosenbergJan 21, 2013
  29. Matthieu MoyJan 21, 2013
  30. Robin RosenbergJan 21, 2013
  31. Junio C HamanoJan 21, 2013
  32. Piotr KrukowieckiJan 21, 2013
  33. Matthieu MoyJan 21, 2013
  34. Matthieu MoyJan 21, 2013
  35. Jonathan NiederJan 21, 2013
  36. Matthieu MoyJan 22, 2013
  37. add: warn when -u or -A is used without filepatternMatthieu Moy, Jan 25, 2013
  38. Junio C HamanoJan 25, 2013
  39. Matthieu MoyJan 27, 2013
  40. Junio C HamanoJan 27, 2013
  41. Matthieu MoyJan 28, 2013
  42. add: warn when -u or -A is used without filepatternMatthieu Moy, Jan 28, 2013
  43. Jonathan NiederJan 28, 2013
  44. Michael J GruberJan 28, 2013
  45. Junio C HamanoJan 28, 2013
  46. Matthieu MoyJan 28, 2013
  47. Junio C HamanoJan 28, 2013
  48. Junio C HamanoFeb 14, 2013
  49. Junio C HamanoFeb 14, 2013
  50. Matthieu MoyFeb 15, 2013
  51. Jonathan NiederJan 27, 2013
  52. Duy NguyenJan 22, 2013
  53. Junio C HamanoJan 22, 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.