Skip to content

Commit fdc97ab

Browse files
committed
git add <pathspec>... defaults to "-A"
Make "git add <pathspec>..." notice paths that have been removed from the working tree, i.e. the same as "git add -A <pathspec>...". Given that "git add <pathspec>" is to update the index with the state of the named part of the working tree as a whole, it makes it more intuitive, and also makes it possible to simplify the advice we give while marking the paths the user finished resolving conflicts with. We used to say "to record removal as a resolution, remove the path from the working tree and say 'git rm'; for all other cases, edit the path in the working tree and say 'git add'", but we can now say "update the path in the working tree and say 'git add'" instead. As promised, this merges the temporary update_files_in_cache() helper function back to add_files_to_cache() function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4c71143 commit fdc97ab

2 files changed

Lines changed: 15 additions & 46 deletions

File tree

Documentation/git-add.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ OPTIONS
5353
Files to add content from. Fileglobs (e.g. `*.c`) can
5454
be given to add all matching files. Also a
5555
leading directory name (e.g. `dir` to add `dir/file1`
56-
and `dir/file2`) can be given to add all files in the
57-
directory, recursively.
56+
and `dir/file2`) can be given to update the index to
57+
match the current state of the directory as a whole (e.g.
58+
specifying `dir` will record not just a file `dir/file1`
59+
modified in the working tree, a file `dir/file2` added to
60+
the working tree, but also a file `dir/file3` removed from
61+
the working tree. Note that older versions of Git used
62+
to ignore removed files; use `--no-all` option if you want
63+
to add modified or new files but ignore removed ones.
5864

5965
-n::
6066
--dry-run::
@@ -129,11 +135,9 @@ of Git, hence the form without <pathspec> should not be used.
129135
files that have been removed from the working tree. This
130136
option is a no-op when no <pathspec> is used.
131137
+
132-
This option is primarily to help the current users of Git, whose
133-
"git add <pathspec>..." ignores removed files. In future versions
134-
of Git, "git add <pathspec>..." will be a synonym to "git add -A
135-
<pathspec>..." and "git add --ignore-removal <pathspec>..." will behave like
136-
today's "git add <pathspec>...", ignoring removed files.
138+
This option is primarily to help users who are used to older
139+
versions of Git, whose "git add <pathspec>..." was a synonym
140+
for "git add --no-all <pathspec>...", i.e. ignored removed files.
137141

138142
-N::
139143
--intent-to-add::

builtin/add.c

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ struct update_callback_data {
2828
int add_errors;
2929
const char *implicit_dot;
3030
size_t implicit_dot_len;
31-
32-
/* only needed for 2.0 transition preparation */
33-
int warn_add_would_remove;
3431
};
3532

3633
static const char *option_with_implicit_dot;
@@ -96,24 +93,6 @@ static int fix_unmerged_status(struct diff_filepair *p,
9693
return DIFF_STATUS_MODIFIED;
9794
}
9895

99-
static const char *add_would_remove_warning = N_(
100-
"You ran 'git add' with neither '-A (--all)' or '--ignore-removal',\n"
101-
"whose behaviour will change in Git 2.0 with respect to paths you removed.\n"
102-
"Paths like '%s' that are\n"
103-
"removed from your working tree are ignored with this version of Git.\n"
104-
"\n"
105-
"* 'git add --ignore-removal <pathspec>', which is the current default,\n"
106-
" ignores paths you removed from your working tree.\n"
107-
"\n"
108-
"* 'git add --all <pathspec>' will let you also record the removals.\n"
109-
"\n"
110-
"Run 'git status' to check the paths you removed from your working tree.\n");
111-
112-
static void warn_add_would_remove(const char *path)
113-
{
114-
warning(_(add_would_remove_warning), path);
115-
}
116-
11796
static void update_callback(struct diff_queue_struct *q,
11897
struct diff_options *opt, void *cbdata)
11998
{
@@ -151,10 +130,6 @@ static void update_callback(struct diff_queue_struct *q,
151130
}
152131
break;
153132
case DIFF_STATUS_DELETED:
154-
if (data->warn_add_would_remove) {
155-
warn_add_would_remove(path);
156-
data->warn_add_would_remove = 0;
157-
}
158133
if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
159134
break;
160135
if (!(data->flags & ADD_CACHE_PRETEND))
@@ -378,7 +353,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
378353
static int verbose, show_only, ignored_too, refresh_only;
379354
static int ignore_add_errors, intent_to_add, ignore_missing;
380355

381-
#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
356+
#define ADDREMOVE_DEFAULT 1
382357
static int addremove = ADDREMOVE_DEFAULT;
383358
static int addremove_explicit = -1; /* unspecified */
384359

@@ -476,20 +451,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
476451
if (addremove && take_worktree_changes)
477452
die(_("-A and -u are mutually incompatible"));
478453

479-
/*
480-
* Warn when "git add pathspec..." was given without "-u" or "-A"
481-
* and pathspec... covers a removed path.
482-
*/
483-
memset(&update_data, 0, sizeof(update_data));
484-
if (!take_worktree_changes && addremove_explicit < 0)
485-
update_data.warn_add_would_remove = 1;
486-
487454
if (!take_worktree_changes && addremove_explicit < 0 && argc)
488-
/*
489-
* Turn "git add pathspec..." to "git add -A pathspec..."
490-
* in Git 2.0 but not yet
491-
*/
492-
; /* addremove = 1; */
455+
/* Turn "git add pathspec..." to "git add -A pathspec..." */
456+
addremove = 1;
493457

494458
if (!show_only && ignore_missing)
495459
die(_("Option --ignore-missing can only be used together with --dry-run"));
@@ -579,6 +543,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
579543

580544
plug_bulk_checkin();
581545

546+
memset(&update_data, 0, sizeof(update_data));
582547
if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) {
583548
/*
584549
* Check for modified files throughout the worktree so

0 commit comments

Comments
 (0)