From: Junio C Hamano Date: Mon, 22 Apr 2013 18:11:45 +0000 (-0700) Subject: Merge branch 'jc/add-2.0-delete-default' (early part) X-Git-Tag: v1.8.3-rc0~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=561954bfa1c1a1c5a76ca59001da331c73c5c141;p=git Merge branch 'jc/add-2.0-delete-default' (early part) Preparatory steps to make "git add " take notice of removed paths that match by default in Git 2.0. * 'jc/add-2.0-delete-default' (early part): git add: rephrase the "removal will cease to be ignored" warning git add: rework the logic to warn "git add ..." default change git add: start preparing for "git add ..." to default to "-A" builtin/add.c: simplify boolean variables --- 561954bfa1c1a1c5a76ca59001da331c73c5c141 diff --cc builtin/add.c index daf02c6aff,20f459a0a3..54cd2d417d --- a/builtin/add.c +++ b/builtin/add.c @@@ -26,52 -26,11 +26,55 @@@ static int take_worktree_changes struct update_callback_data { int flags; 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; +static const char *short_option_with_implicit_dot; + +static void warn_pathless_add(void) +{ + static int shown; + assert(option_with_implicit_dot && short_option_with_implicit_dot); + + if (shown) + return; + shown = 1; + + /* + * 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, the behavior can be changed + * to tree-wide, keeping the warning for a while, and + * eventually we can drop the warning. + */ + 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.\n" + ""), + option_with_implicit_dot, short_option_with_implicit_dot, + option_with_implicit_dot, short_option_with_implicit_dot, + option_with_implicit_dot, short_option_with_implicit_dot); +} + static int fix_unmerged_status(struct diff_filepair *p, struct update_callback_data *data) { @@@ -141,24 -106,10 +166,11 @@@ static void update_callback(struct diff } } - int add_files_to_cache(const char *prefix, const char **pathspec, int flags) + static void update_files_in_cache(const char *prefix, const char **pathspec, + struct update_callback_data *data) { - struct update_callback_data data; struct rev_info rev; + - memset(&data, 0, sizeof(data)); - data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT; - if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) { - /* - * Check for modified files throughout the worktree so - * update_callback has a chance to warn about changes - * outside the cwd. - */ - data.implicit_dot = prefix; - data.implicit_dot_len = strlen(prefix); - pathspec = NULL; - } - init_revisions(&rev, prefix); setup_revisions(0, NULL, &rev, NULL); init_pathspec(&rev.prune_data, pathspec); @@@ -415,7 -396,9 +440,8 @@@ int cmd_add(int argc, const char **argv 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; + int implicit_dot = 0; + struct update_callback_data update_data; git_config(add_config, NULL); @@@ -521,8 -525,10 +568,20 @@@ plug_bulk_checkin(); - exit_status |= add_files_to_cache(prefix, pathspec, flags); - update_data.flags = flags; ++ if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) { ++ /* ++ * Check for modified files throughout the worktree so ++ * update_callback has a chance to warn about changes ++ * outside the cwd. ++ */ ++ update_data.implicit_dot = prefix; ++ update_data.implicit_dot_len = strlen(prefix); ++ pathspec = NULL; ++ } ++ update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT; + update_files_in_cache(prefix, pathspec, &update_data); + exit_status |= !!update_data.add_errors; if (add_new_files) exit_status |= add_files(&dir, flags);