From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Robin Rosenberg <robin.rosenberg@dewire.com>,
Piotr Krukowiecki <piotr.krukowiecki@gmail.com>,
Eric James Michael Ritz <lobbyjones@gmail.com>,
Tomas Carnecky <tomas.carnecky@gmail.com>,
Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH v2] add: warn when -u or -A is used without filepattern
Date: Fri, 25 Jan 2013 11:49:38 +0100 [thread overview]
Message-ID: <1359110978-20054-1-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <vpq1uddoedj.fsf@grenoble-inp.fr>
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.
When the command is called from the root of the tree, there is no
ambiguity and no need to change the behavior, hence no need to warn.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
Changes since v1:
* Do not warn from the root of the tree.
* Say explicitely "Git 2.0" to announce the change.
(plus fix a C99 style issue)
Documentation/git-add.txt | 7 ++++---
builtin/add.c | 36 +++++++++++++++++++++++++++++++++++-
2 files changed, 39 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..8252d19 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -363,6 +363,33 @@ static int add_files(struct dir_struct *dir, int flags)
return exit_status;
}
+static void warn_pathless_add(const char *option_name) {
+ /*
+ * 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 from a subdirectory of the\n"
+ "tree will change in Git 2.0 and shouldn't be used anymore.\n"
+ "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_name,
+ option_name,
+ option_name);
+}
+
int cmd_add(int argc, const char **argv, const char *prefix)
{
int exit_status = 0;
@@ -373,6 +400,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,8 +420,14 @@ 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) {
static const char *here[2] = { ".", NULL };
+ if (prefix)
+ warn_pathless_add(option_with_implicit_dot);
argc = 1;
argv = here;
}
--
1.8.0.1.527.gd366564.dirty
next prev parent reply other threads:[~2013-01-25 10:50 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-19 21:35 [RFC] git rm -u Eric James Michael Ritz
2013-01-19 21:47 ` Tomas Carnecky
2013-01-19 21:49 ` Antoine Pelisse
2013-01-19 21:56 ` Eric James Michael Ritz
2013-02-25 6:54 ` Junio C Hamano
2013-02-25 18:54 ` Antoine Pelisse
2013-02-25 19:07 ` Matthieu Moy
2013-02-25 19:21 ` Antoine Pelisse
2013-02-25 19:39 ` Matthieu Moy
2013-02-25 19:47 ` Junio C Hamano
2013-01-19 21:49 ` Jonathan Nieder
2013-01-19 22:01 ` Eric James Michael Ritz
2013-01-20 11:32 ` Matthieu Moy
2013-01-20 18:42 ` Junio C Hamano
2013-01-20 21:27 ` Junio C Hamano
2013-01-20 22:17 ` Martin von Zweigbergk
2013-01-21 8:44 ` Matthieu Moy
2013-01-20 18:53 ` Junio C Hamano
2013-01-20 19:21 ` Eric James Michael Ritz
2013-01-21 8:09 ` Piotr Krukowiecki
2013-01-21 8:37 ` Matthieu Moy
2013-01-21 9:23 ` Junio C Hamano
2013-01-21 19:01 ` Junio C Hamano
2013-01-21 20:03 ` Matthieu Moy
2013-01-21 23:18 ` Junio C Hamano
2013-01-21 19:10 ` Piotr Krukowiecki
2013-01-21 12:00 ` [RFC/PATCH] add: warn when -u or -A is used without filepattern Matthieu Moy
2013-01-21 15:00 ` Robin Rosenberg
2013-01-21 15:16 ` Matthieu Moy
2013-01-21 20:29 ` Robin Rosenberg
2013-01-21 19:12 ` Junio C Hamano
2013-01-21 19:34 ` Piotr Krukowiecki
2013-01-21 20:06 ` Matthieu Moy
2013-01-21 20:10 ` Matthieu Moy
2013-01-21 22:22 ` Jonathan Nieder
2013-01-22 7:39 ` Matthieu Moy
2013-01-25 10:49 ` Matthieu Moy [this message]
2013-01-25 19:27 ` [PATCH v2] " Junio C Hamano
2013-01-27 16:10 ` Matthieu Moy
2013-01-27 20:33 ` Junio C Hamano
2013-01-28 8:48 ` Matthieu Moy
2013-01-28 9:16 ` [PATCH v3] " Matthieu Moy
2013-01-28 9:20 ` Jonathan Nieder
2013-01-28 12:47 ` Michael J Gruber
2013-01-28 18:07 ` Junio C Hamano
2013-01-28 18:25 ` Matthieu Moy
2013-01-28 18:31 ` Junio C Hamano
2013-02-14 23:36 ` Junio C Hamano
2013-02-14 23:55 ` Junio C Hamano
2013-02-15 10:00 ` Matthieu Moy
2013-01-27 12:22 ` [PATCH v2] " Jonathan Nieder
2013-01-22 1:10 ` [RFC/PATCH] " Duy Nguyen
2013-01-22 1:51 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359110978-20054-1-git-send-email-Matthieu.Moy@imag.fr \
--to=matthieu.moy@imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=lobbyjones@gmail.com \
--cc=piotr.krukowiecki@gmail.com \
--cc=robin.rosenberg@dewire.com \
--cc=tomas.carnecky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).