diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-02-04 10:25:13 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-02-04 10:25:14 -0800 |
commit | 27d46a70724ef5e087863c3db35eb7ca9c084c2c (patch) | |
tree | c5d5c9a2ba819662fb939bfb8ff195f718749950 /builtin | |
parent | 370855e967e21d9c5b70df7b5cd3756c7bed5c7c (diff) | |
parent | 0fa2eb530fb748774c5b2f309a471cf048b8d9d9 (diff) | |
download | git-27d46a70724ef5e087863c3db35eb7ca9c084c2c.tar.gz |
Merge branch 'mm/add-u-A-sans-pathspec'
Forbid "git add -u" and "git add -A" without pathspec run from a
subdirectory, to train people to type "." (or ":/") to make the
choice of default does not matter.
* mm/add-u-A-sans-pathspec:
add: warn when -u or -A is used without pathspec
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/add.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/builtin/add.c b/builtin/add.c index 7cb6cca56d..7738025a2e 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -321,6 +321,35 @@ 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) { + /* + * To be consistent 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 (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" + "\n" + " git add %s :/\n" + " (or git add %s :/)\n" + "\n" + "To restrict the command to the current directory, run:\n" + "\n" + " git add %s .\n" + " (or git add %s .)\n" + "\n" + "With the current Git version, the command is restricted to the current directory."), + option_name, short_name, + option_name, short_name, + option_name, short_name); +} + int cmd_add(int argc, const char **argv, const char *prefix) { int exit_status = 0; @@ -331,6 +360,8 @@ 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; + const char *short_option_with_implicit_dot = NULL; git_config(add_config, NULL); @@ -350,8 +381,19 @@ 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"; + short_option_with_implicit_dot = "-A"; + } + if (take_worktree_changes) { + option_with_implicit_dot = "--update"; + short_option_with_implicit_dot = "-u"; + } + if (option_with_implicit_dot && !argc) { static const char *here[2] = { ".", NULL }; + if (prefix) + warn_pathless_add(option_with_implicit_dot, + short_option_with_implicit_dot); argc = 1; argv = here; } |