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

jc/add-2.0-delete-default (Re: What's cooking in git.git (Apr 2013, #05; Mon, 15))

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 21, 2013, 07:39 UTC
Message-ID
<20130421073918.GD10429@elie.Belkin>
In-Reply-To
<20130419213455.GB20873@sigill.intra.peff.net>
> On Fri, Apr 19, 2013 at 10:25:46AM -0700, Junio C Hamano wrote:
>>> Junio C Hamano wrote:
Show 15 quoted lines
>>>>     You ran 'git add' with neither '-A (--all)' or '--no-all', whose
>>>>     behaviour will change in Git 2.0 with respect to paths you
>>>>     removed from your working tree.
>>>>
>>>>     * 'git add --no-all <pathspec>', which is the current default,
>>>>       ignores paths you removed from your working tree.
>>>>
>>>>     * 'git add --all <pathspec>' will let you also record the
>>>>       removals.
>>>>
>>>>     The removed paths (e.g. '%s') are ignored with this version of Git.
>>>>     Run 'git status' to remind yourself what paths you have removed
>>>>     from your working tree.
>>>>
>>>> or something?
[...]
>>                                     Somebody good at phrasing needs
>> to trim it down without losing the essense.

By the way, it was mentioned on IRC that the above is a bit odd for a different reason: the option --no-all that maintains the old behavior is not intuitively named.

How about something like this?
	warning: "git add" run on path with files removed (e.g., '%s')
	hint: use "git add --ignore-removals <pathspec>" to ignore removals
	hint: or "git add --no-ignore-removals <pathspec>" to notice them
	hint: --ignore-removals is the default but this will change soon
	hint: see git-add(1) for details

Then the --ignore-removals option could be added using a patch like the following.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/git-add.txt | 24 +++++++++++++++---------
 builtin/add.c             | 28 +++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index b0944e57..8607cf37 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -9,7 +9,8 @@ SYNOPSIS
 --------
 [verse]
 'git add' [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
-	  [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
+	  [--edit | -e] [--update | -u] [--no-ignore-removals | -A]
+	  [--intent-to-add | -N]
 	  [--refresh] [--ignore-errors] [--ignore-missing] [--]
 	  [<pathspec>...]
 
@@ -109,17 +110,22 @@ If no <pathspec> is given, the current version of Git defaults to
 and its subdirectories. This default will change in a future version
 of Git, hence the form without <pathspec> should not be used.
 
+--ignore-removals::
+--no-ignore-removals::
 -A::
 --all::
-	Update the index not only where the working tree has a file
-	matching <pathspec> but also where the index already has an
-	entry.	This adds, modifies, and removes index entries to
-	match the working tree.
+	Update the index only where the working tree has a file
+	matching <pathspec>.  This adds and modifies index entries
+	to match the working tree but ignores removed files.
 +
-If no <pathspec> is given, the current version of Git defaults to
-"."; in other words, update all files in the current directory
-and its subdirectories. This default will change in a future version
-of Git, hence the form without <pathspec> should not be used.
+This is currently the default.  Git 2.0 will change the default
+to --no-ignore-removals.
++
+With --no-ignore-removals (and its historical synonyms `-A` and
+`--all`), if no <pathspec> is given, the current version of Git
+defaults to "."; in other words, update all files in the current
+directory and its subdirectories. This default will change in a future
+version of Git, hence the form without <pathspec> should not be used.
 
 -N::
 --intent-to-add::
diff --git a/builtin/add.c b/builtin/add.c
index ab1c9e8f..4a4e71ad 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -28,6 +28,14 @@ struct update_callback_data {
 	int add_errors;
 };
 
+static int parse_opt_neg_tertiary(const struct option *opt, const char *arg,
+				  int unset)
+{
+	int *target = opt->value;
+	*target = unset ? 1 : 2;
+	return 0;
+}
+
 static int fix_unmerged_status(struct diff_filepair *p,
 			       struct update_callback_data *data)
 {
@@ -271,7 +279,8 @@ static const char ignore_error[] =
 N_("The following paths are ignored by one of your .gitignore files:\n");
 
 static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
-static int ignore_add_errors, addremove, intent_to_add, ignore_missing = 0;
+static int ignore_add_errors, intent_to_add, ignore_missing = 0;
+static int ignore_removals, addremove;
 
 static struct option builtin_add_options[] = {
 	OPT__DRY_RUN(&show_only, N_("dry run")),
@@ -283,10 +292,12 @@ static struct option builtin_add_options[] = {
 	OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files")),
 	OPT_BOOLEAN('u', "update", &take_worktree_changes, N_("update tracked files")),
 	OPT_BOOLEAN('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
-	OPT_BOOLEAN('A', "all", &addremove, N_("add changes from all tracked and untracked files")),
+	OPT_UYN( 0 , "ignore-removals", &ignore_removals, N_("do not record removal of tracked files")),
 	OPT_BOOLEAN( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
 	OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
 	OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
+	{ OPTION_CALLBACK, 'A', "all", &ignore_removals, NULL, N_("synonym for --no-ignore-removals"),
+	  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, &parse_opt_neg_tertiary },
 	OPT_END(),
 };
 
@@ -377,8 +388,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	argc--;
 	argv++;
 
+	if (ignore_removals == 2) {	/* --no-ignore-removals, or -A */
+		addremove = 1;
+		ignore_removals = 0;
+	}
+	if (ignore_removals && take_worktree_changes)
+		/*
+		 * NEEDSWORK: "git add -u --ignore-removals" should mean
+		 * "git diff --diff-filter=M | git apply --cached"
+		 */
+		die(_("--ignore-removals cannot be used with --update"));
 	if (addremove && take_worktree_changes)
-		die(_("-A and -u are mutually incompatible"));
+		/* -u --no-ignore-removals is the same as -u */
+		addremove = 0;
 	if (!show_only && ignore_missing)
 		die(_("Option --ignore-missing can only be used together with --dry-run"));
 	if (addremove) {
-- 
1.8.2.1
Previous: Junio C HamanoNext: Junio C Hamano
Message 69 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.