[PATCH] add: allow users to silence Git 2.0 warnings about "add -u"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When "git add -u" is invoked from a subdirectory it prints a
loud warning message about an upcoming Git 2.0 behavior change.
Some users do not care to be warned.  Accomodate them.

The "add.silence-pathless-warnings" configuration variable can
now be used to silence this warning.

Signed-off-by: David Aguilar <davvid@xxxxxxxxx>
---
I found the warning a informative but also a little annoying.
I can imagine others might as well.

I would also like to change the warning message to mention what the Git 2.0
behavior will be (which it does not mention), but I realize that the string
has already been translated.  That can be a follow-on patch if this is seen as
a worthwhile change, but might not be worth the trouble since it's a problem
which will go away in 2.0.

 Documentation/config.txt |  7 +++++++
 builtin/add.c            |  8 +++++++-
 t/t2200-add-update.sh    | 11 +++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3bb53da..b6ed859 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -648,6 +648,13 @@ core.abbrev::
 	for abbreviated object names to stay unique for sufficiently long
 	time.
 
+add.silence-pathless-warnings::
+	Tells 'git add' to silence warnings when 'git add -u' is used in
+	a subdirectory without specifying a path.  Git 2.0 updates the
+	whole tree.  Git 1.x updates the current directory only, and warns
+	about the upcoming change unless this variable is set to true.
+	False by default, and ignored by Git 2.0.
+
 add.ignore-errors::
 add.ignoreErrors::
 	Tells 'git add' to continue adding files when some files cannot be
diff --git a/builtin/add.c b/builtin/add.c
index 0dd014e..01b9cac 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -272,6 +272,7 @@ 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 silence_pathless_warnings;
 
 static struct option builtin_add_options[] = {
 	OPT__DRY_RUN(&show_only, N_("dry run")),
@@ -296,6 +297,8 @@ static int add_config(const char *var, const char *value, void *cb)
 	    !strcmp(var, "add.ignore-errors")) {
 		ignore_add_errors = git_config_bool(var, value);
 		return 0;
+	} else if (!strcmp(var, "add.silence-pathless-warnings")) {
+		silence_pathless_warnings = git_config_bool(var, value);
 	}
 	return git_default_config(var, value, cb);
 }
@@ -321,7 +324,8 @@ static int add_files(struct dir_struct *dir, int flags)
 	return exit_status;
 }
 
-static void warn_pathless_add(const char *option_name, const char *short_name) {
+static void warn_pathless_add(const char *option_name, const char *short_name)
+{
 	/*
 	 * To be consistent with "git add -p" and most Git
 	 * commands, we should default to being tree-wide, but
@@ -332,6 +336,8 @@ static void warn_pathless_add(const char *option_name, const char *short_name) {
 	 * turned into a die(...), and eventually we may
 	 * reallow the command with a new behavior.
 	 */
+	if (silence_pathless_warnings)
+		return;
 	warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
 		  "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
 		  "To add content for the whole tree, run:\n"
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index 4cdebda..779dbe7 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -171,4 +171,15 @@ test_expect_success '"add -u non-existent" should fail' '
 	! (git ls-files | grep "non-existent")
 '
 
+test_expect_success 'add.silence-pathless-warnings configuration variable' '
+	: >expect &&
+	test_config add.silence-pathless-warnings true &&
+	(
+		cd dir1 &&
+		echo more >>sub2 &&
+		git add -u
+	) >actual 2>&1 &&
+	test_cmp expect actual
+'
+
 test_done
-- 
1.8.2.rc0.22.gb3600c3.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]