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

[PATCH 3/2] git add <pathspec>... defaults to "-A"

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 22, 2013, 22:41 UTC
Message-ID
<7vr4i2mbmb.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<1366663435-13598-1-git-send-email-gitster@pobox.com>

Make "git add <pathspec>..." notice paths that have been removed from the working tree, i.e. a synonym to "git add -A <pathspec>...".

Given that "git add <pathspec>" is to update the index with the state of the named part of the working tree as a whole, it makes it more intuitive, and also makes it possible to simplify the advice we give while marking the paths the user finished resolving conflicts with. We used to say "to record removal as a resolution, remove the path from the working tree and say 'git rm'; for all other cases, edit the path in the working tree and say 'git add'", but we can now say "update the path in the working tree and say 'git add'" instead.

As promised, this merges the temporary update_files_in_cache() helper function back to add_files_to_cache() function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This comes on top of the previous two meant for 1.8.3, but should
   wait until Git 2.0.  You can see that it still has conflicts with
   Jonathan's jn/add-2.0-u-A-sans-pathspec topic, but there is a
   resolution already prepared on 'pu'.
 Documentation/git-add.txt | 18 +++++++++++-------
 builtin/add.c             | 43 ++++---------------------------------------
 2 files changed, 15 insertions(+), 46 deletions(-)
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 48754cb..77ad391 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -53,8 +53,14 @@ OPTIONS
 	Files to add content from.  Fileglobs (e.g. `*.c`) can
 	be given to add all matching files.  Also a
 	leading directory name (e.g. `dir` to add `dir/file1`
-	and `dir/file2`) can be given to add all files in the
-	directory, recursively.
+	and `dir/file2`) can be given to update the index to
+	match the current state of the directory as a whole (e.g.
+	specifying `dir` will record not just a file `dir/file1`
+	modified in the working tree, a file `dir/file2` added to
+	the working tree, but also a file `dir/file3` removed from
+	the working tree.  Note that older versions of 	Git used
+	to ignore removed files; use `--no-all` option if you want
+	to add modified or new files but ignore removed	ones.
 
 -n::
 --dry-run::
@@ -129,11 +135,9 @@ of Git, hence the form without <pathspec> should not be used.
 	files that have been removed from the working tree.  This
 	option is a no-op when no <pathspec> is used.
 +
-This option is primarily to help the current users of Git, whose
-"git add <pathspec>..." ignores removed files.  In future versions
-of Git, "git add <pathspec>..." will be a synonym to "git add -A
-<pathspec>..." and "git add --ignore-removal <pathspec>..." will behave like
-today's "git add <pathspec>...", ignoring removed files.
+This option is primarily to help users who are used to older
+versions of Git, whose "git add <pathspec>..." was a synonym
+to "git add --no-all <pathspec>...", i.e. ignored removed files.
 
 -N::
 --intent-to-add::
diff --git a/builtin/add.c b/builtin/add.c
index c55615b..22c5ff5 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -28,9 +28,6 @@ struct update_callback_data {
 	int add_errors;
 	const char *implicit_dot;
 	size_t implicit_dot_len;
-
-	/* only needed for 2.0 transition preparation */
-	int warn_add_would_remove;
 };
 
 static const char *option_with_implicit_dot;
@@ -96,24 +93,6 @@ static int fix_unmerged_status(struct diff_filepair *p,
 		return DIFF_STATUS_MODIFIED;
 }
 
-static const char *add_would_remove_warning = N_(
-	"You ran 'git add' with neither '-A (--all)' or '--ignore-removal',\n"
-"whose behaviour will change in Git 2.0 with respect to paths you removed.\n"
-"Paths like '%s' that are\n"
-"removed from your working tree are ignored with this version of Git.\n"
-"\n"
-"* 'git add --ignore-removal <pathspec>', which is the current default,\n"
-"  ignores paths you removed from your working tree.\n"
-"\n"
-"* 'git add --all <pathspec>' will let you also record the removals.\n"
-"\n"
-"Run 'git status' to check the paths you removed from your working tree.\n");
-
-static void warn_add_would_remove(const char *path)
-{
-	warning(_(add_would_remove_warning), path);
-}
-
 static void update_callback(struct diff_queue_struct *q,
 			    struct diff_options *opt, void *cbdata)
 {
@@ -151,10 +130,6 @@ static void update_callback(struct diff_queue_struct *q,
 			}
 			break;
 		case DIFF_STATUS_DELETED:
-			if (data->warn_add_would_remove) {
-				warn_add_would_remove(path);
-				data->warn_add_would_remove = 0;
-			}
 			if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
 				break;
 			if (!(data->flags & ADD_CACHE_PRETEND))
@@ -378,7 +353,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
 static int verbose, show_only, ignored_too, refresh_only;
 static int ignore_add_errors, intent_to_add, ignore_missing;
 
-#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
+#define ADDREMOVE_DEFAULT 1
 static int addremove = ADDREMOVE_DEFAULT;
 static int addremove_explicit = -1; /* unspecified */
 
@@ -476,20 +451,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (addremove && take_worktree_changes)
 		die(_("-A and -u are mutually incompatible"));
 
-	/*
-	 * Warn when "git add pathspec..." was given without "-u" or "-A"
-	 * and pathspec... covers a removed path.
-	 */
-	memset(&update_data, 0, sizeof(update_data));
-	if (!take_worktree_changes && addremove_explicit < 0)
-		update_data.warn_add_would_remove = 1;
-
 	if (!take_worktree_changes && addremove_explicit < 0 && argc)
-		/*
-		 * Turn "git add pathspec..." to "git add -A pathspec..."
-		 * in Git 2.0 but not yet
-		 */
-		; /* addremove = 1; */
+		/* Turn "git add pathspec..." to "git add -A pathspec..." */
+		addremove = 1;
 
 	if (!show_only && ignore_missing)
 		die(_("Option --ignore-missing can only be used together with --dry-run"));
@@ -579,6 +543,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
 	plug_bulk_checkin();
 
+	memset(&update_data, 0, sizeof(update_data));
 	if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) {
 		/*
 		 * Check for modified files throughout the worktree so
-- 
1.8.2.1-740-ga5571a3
Previous: Junio C HamanoNext: Eric Sunshine
Message 75 of 85 in “What's cooking in git.git (Apr 2013, #05; Mon, 15)”
  1. Junio C HamanoApr 15, 2013
  2. Felipe ContrerasApr 15, 2013
  3. Junio C HamanoApr 15, 2013
  4. Felipe ContrerasApr 15, 2013
  5. Junio C HamanoApr 16, 2013
  6. Felipe ContrerasApr 16, 2013
  7. Thomas RastApr 16, 2013
  8. Felipe ContrerasApr 16, 2013
  9. Junio C HamanoApr 16, 2013
  10. Felipe ContrerasApr 16, 2013
  11. Phil HordApr 16, 2013
  12. Felipe ContrerasApr 16, 2013
  13. Phil HordApr 16, 2013
  14. Junio C HamanoApr 17, 2013
  15. Felipe ContrerasApr 17, 2013
  16. Junio C HamanoApr 17, 2013
  17. Felipe ContrerasApr 18, 2013
  18. Matthieu MoyApr 18, 2013
  19. Felipe ContrerasApr 18, 2013
  20. Ramkumar RamachandraApr 18, 2013
  21. Felipe ContrerasApr 18, 2013
  22. Ramkumar RamachandraApr 18, 2013
  23. Felipe ContrerasApr 18, 2013
  24. Ramkumar RamachandraApr 18, 2013
  25. Felipe ContrerasApr 18, 2013
  26. Ramkumar RamachandraApr 18, 2013
  27. Felipe ContrerasApr 18, 2013
  28. Ramkumar RamachandraApr 23, 2013
  29. Felipe ContrerasApr 23, 2013
  30. Phil HordApr 18, 2013
  31. Felipe ContrerasApr 18, 2013
  32. Phil HordApr 19, 2013
  33. Felipe ContrerasApr 20, 2013
  34. Jeff KingApr 15, 2013
  35. Øyvind A. HolmApr 15, 2013
  36. Jeff KingApr 16, 2013
  37. Jeff KingApr 16, 2013
  38. Eric SunshineApr 16, 2013
  39. Junio C HamanoApr 16, 2013
  40. Drew NorthupApr 16, 2013
  41. "What's cooking" between #05 and #06Junio C Hamano, Apr 16, 2013
  42. John KeepingApr 17, 2013
  43. Junio C HamanoApr 17, 2013
  44. Jens LehmannApr 17, 2013
  45. John KeepingApr 18, 2013
  46. Lukas FleischerApr 17, 2013
  47. Junio C HamanoApr 17, 2013
  48. Thomas RastApr 17, 2013
  49. Junio C HamanoApr 17, 2013
  50. Thomas RastApr 17, 2013
  51. Junio C HamanoApr 17, 2013
  52. Junio C HamanoApr 17, 2013
  53. Jeff KingApr 17, 2013
  54. Junio C HamanoApr 18, 2013
  55. git add <pathspec>... defaults to "-A"Junio C Hamano, Apr 18, 2013
  56. Jeff KingApr 18, 2013
  57. Junio C HamanoApr 18, 2013
  58. Jeff KingApr 18, 2013
  59. Junio C HamanoApr 18, 2013
  60. Jeff KingApr 18, 2013
  61. Junio C HamanoApr 18, 2013
  62. Jeff KingApr 18, 2013
  63. Junio C HamanoApr 18, 2013
  64. Jeff KingApr 19, 2013
  65. Jonathan NiederApr 19, 2013
  66. Junio C HamanoApr 19, 2013
  67. Jeff KingApr 19, 2013
  68. Junio C HamanoApr 19, 2013
  69. jc/add-2.0-delete-default (Re: What's cooking in git.git (Apr 2013, #05; Mon, 15))Jonathan Nieder, Apr 21, 2013
  70. Junio C HamanoApr 22, 2013
  71. Junio C HamanoApr 22, 2013
  72. 0/2 "git add -A/--no-all" finishing touchesJunio C Hamano, Apr 22, 2013
  73. 1/2 git add: --ignore-removal is a better named --no-allJunio C Hamano, Apr 22, 2013
  74. 2/2 git add: rephrase -A/--no-all warningJunio C Hamano, Apr 22, 2013
  75. 3/2 git add <pathspec>... defaults to "-A"Junio C Hamano, Apr 22, 2013
  76. Eric SunshineApr 23, 2013
  77. Junio C HamanoApr 25, 2013
  78. Junio C HamanoApr 25, 2013
  79. Jonathan NiederApr 25, 2013
  80. Junio C HamanoApr 25, 2013
  81. Junio C HamanoApr 25, 2013
  82. Jonathan NiederApr 25, 2013
  83. Junio C HamanoApr 26, 2013
  84. Junio C HamanoApr 26, 2013
  85. Jonathan NiederApr 26, 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.