Skip to content

Commit 160c4b1

Browse files
committed
Merge branch 'jc/add-2.0-ignore-removal'
"git add <pathspec>" is the same as "git add -A <pathspec>" now, i.e. it does not ignore removals from the directory specified.
2 parents 053a6b1 + fdc97ab commit 160c4b1

2 files changed

Lines changed: 23 additions & 64 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 @@ subdirectories).
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: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ static int take_worktree_changes;
2626
struct update_callback_data {
2727
int flags;
2828
int add_errors;
29-
/* only needed for 2.0 transition preparation */
30-
int warn_add_would_remove;
3129
};
3230

3331
static int fix_unmerged_status(struct diff_filepair *p,
@@ -51,24 +49,6 @@ static int fix_unmerged_status(struct diff_filepair *p,
5149
return DIFF_STATUS_MODIFIED;
5250
}
5351

54-
static const char *add_would_remove_warning = N_(
55-
"You ran 'git add' with neither '-A (--all)' or '--ignore-removal',\n"
56-
"whose behaviour will change in Git 2.0 with respect to paths you removed.\n"
57-
"Paths like '%s' that are\n"
58-
"removed from your working tree are ignored with this version of Git.\n"
59-
"\n"
60-
"* 'git add --ignore-removal <pathspec>', which is the current default,\n"
61-
" ignores paths you removed from your working tree.\n"
62-
"\n"
63-
"* 'git add --all <pathspec>' will let you also record the removals.\n"
64-
"\n"
65-
"Run 'git status' to check the paths you removed from your working tree.\n");
66-
67-
static void warn_add_would_remove(const char *path)
68-
{
69-
warning(_(add_would_remove_warning), path);
70-
}
71-
7252
static void update_callback(struct diff_queue_struct *q,
7353
struct diff_options *opt, void *cbdata)
7454
{
@@ -90,10 +70,6 @@ static void update_callback(struct diff_queue_struct *q,
9070
}
9171
break;
9272
case DIFF_STATUS_DELETED:
93-
if (data->warn_add_would_remove) {
94-
warn_add_would_remove(path);
95-
data->warn_add_would_remove = 0;
96-
}
9773
if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
9874
break;
9975
if (!(data->flags & ADD_CACHE_PRETEND))
@@ -105,31 +81,24 @@ static void update_callback(struct diff_queue_struct *q,
10581
}
10682
}
10783

108-
static void update_files_in_cache(const char *prefix,
109-
const struct pathspec *pathspec,
110-
struct update_callback_data *data)
84+
int add_files_to_cache(const char *prefix,
85+
const struct pathspec *pathspec, int flags)
11186
{
87+
struct update_callback_data data;
11288
struct rev_info rev;
11389

90+
memset(&data, 0, sizeof(data));
91+
data.flags = flags;
92+
11493
init_revisions(&rev, prefix);
11594
setup_revisions(0, NULL, &rev, NULL);
11695
if (pathspec)
11796
copy_pathspec(&rev.prune_data, pathspec);
11897
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
11998
rev.diffopt.format_callback = update_callback;
120-
rev.diffopt.format_callback_data = data;
99+
rev.diffopt.format_callback_data = &data;
121100
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
122101
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
123-
}
124-
125-
int add_files_to_cache(const char *prefix,
126-
const struct pathspec *pathspec, int flags)
127-
{
128-
struct update_callback_data data;
129-
130-
memset(&data, 0, sizeof(data));
131-
data.flags = flags;
132-
update_files_in_cache(prefix, pathspec, &data);
133102
return !!data.add_errors;
134103
}
135104

@@ -265,7 +234,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
265234
static int verbose, show_only, ignored_too, refresh_only;
266235
static int ignore_add_errors, intent_to_add, ignore_missing;
267236

268-
#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
237+
#define ADDREMOVE_DEFAULT 1
269238
static int addremove = ADDREMOVE_DEFAULT;
270239
static int addremove_explicit = -1; /* unspecified */
271240

@@ -338,7 +307,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
338307
int add_new_files;
339308
int require_pathspec;
340309
char *seen = NULL;
341-
struct update_callback_data update_data;
342310

343311
git_config(add_config, NULL);
344312

@@ -362,25 +330,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
362330
if (addremove && take_worktree_changes)
363331
die(_("-A and -u are mutually incompatible"));
364332

365-
/*
366-
* Warn when "git add pathspec..." was given without "-u" or "-A"
367-
* and pathspec... covers a removed path.
368-
*/
369-
memset(&update_data, 0, sizeof(update_data));
370-
if (!take_worktree_changes && addremove_explicit < 0)
371-
update_data.warn_add_would_remove = 1;
372-
373333
if (!take_worktree_changes && addremove_explicit < 0 && argc)
374-
/*
375-
* Turn "git add pathspec..." to "git add -A pathspec..."
376-
* in Git 2.0 but not yet
377-
*/
378-
; /* addremove = 1; */
334+
/* Turn "git add pathspec..." to "git add -A pathspec..." */
335+
addremove = 1;
379336

380337
if (!show_only && ignore_missing)
381338
die(_("Option --ignore-missing can only be used together with --dry-run"));
382339

383-
if ((addremove || take_worktree_changes) && !argc) {
340+
if ((0 < addremove_explicit || take_worktree_changes) && !argc) {
384341
static const char *whole[2] = { ":/", NULL };
385342
argc = 1;
386343
argv = whole;
@@ -478,10 +435,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
478435

479436
plug_bulk_checkin();
480437

481-
update_data.flags = flags;
482-
update_files_in_cache(prefix, &pathspec, &update_data);
438+
exit_status |= add_files_to_cache(prefix, &pathspec, flags);
483439

484-
exit_status |= !!update_data.add_errors;
485440
if (add_new_files)
486441
exit_status |= add_files(&dir, flags);
487442

0 commit comments

Comments
 (0)