Skip to content

Commit 053a6b1

Browse files
committed
Merge branch 'jn/add-2.0-u-A-sans-pathspec'
"git add -u" and "git add -A" without any pathspec is a tree-wide operation now, even when they are run in a subdirectory of the working tree.
2 parents 009055f + 808d3d7 commit 053a6b1

File tree

4 files changed

+19
-122
lines changed

4 files changed

+19
-122
lines changed

Documentation/git-add.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ apply to the index. See EDITING PATCHES below.
104104
<pathspec>. This removes as well as modifies index entries to
105105
match the working tree, but adds no new files.
106106
+
107-
If no <pathspec> is given, the current version of Git defaults to
108-
"."; in other words, update all tracked files in the current directory
109-
and its subdirectories. This default will change in a future version
110-
of Git, hence the form without <pathspec> should not be used.
107+
If no <pathspec> is given when `-u` option is used, all
108+
tracked files in the entire working tree are updated (old versions
109+
of Git used to limit the update to the current directory and its
110+
subdirectories).
111111

112112
-A::
113113
--all::
@@ -117,10 +117,10 @@ of Git, hence the form without <pathspec> should not be used.
117117
entry. This adds, modifies, and removes index entries to
118118
match the working tree.
119119
+
120-
If no <pathspec> is given, the current version of Git defaults to
121-
"."; in other words, update all files in the current directory
122-
and its subdirectories. This default will change in a future version
123-
of Git, hence the form without <pathspec> should not be used.
120+
If no <pathspec> is given when `-A` option is used, all
121+
files in the entire working tree are updated (old versions
122+
of Git used to limit the update to the current directory and its
123+
subdirectories).
124124

125125
--no-all::
126126
--ignore-removal::

builtin/add.c

Lines changed: 9 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -26,55 +26,10 @@ static int take_worktree_changes;
2626
struct update_callback_data {
2727
int flags;
2828
int add_errors;
29-
const char *implicit_dot;
30-
size_t implicit_dot_len;
31-
3229
/* only needed for 2.0 transition preparation */
3330
int warn_add_would_remove;
3431
};
3532

36-
static const char *option_with_implicit_dot;
37-
static const char *short_option_with_implicit_dot;
38-
39-
static void warn_pathless_add(void)
40-
{
41-
static int shown;
42-
assert(option_with_implicit_dot && short_option_with_implicit_dot);
43-
44-
if (shown)
45-
return;
46-
shown = 1;
47-
48-
/*
49-
* To be consistent with "git add -p" and most Git
50-
* commands, we should default to being tree-wide, but
51-
* this is not the original behavior and can't be
52-
* changed until users trained themselves not to type
53-
* "git add -u" or "git add -A". For now, we warn and
54-
* keep the old behavior. Later, the behavior can be changed
55-
* to tree-wide, keeping the warning for a while, and
56-
* eventually we can drop the warning.
57-
*/
58-
warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
59-
"subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
60-
"To add content for the whole tree, run:\n"
61-
"\n"
62-
" git add %s :/\n"
63-
" (or git add %s :/)\n"
64-
"\n"
65-
"To restrict the command to the current directory, run:\n"
66-
"\n"
67-
" git add %s .\n"
68-
" (or git add %s .)\n"
69-
"\n"
70-
"With the current Git version, the command is restricted to "
71-
"the current directory.\n"
72-
""),
73-
option_with_implicit_dot, short_option_with_implicit_dot,
74-
option_with_implicit_dot, short_option_with_implicit_dot,
75-
option_with_implicit_dot, short_option_with_implicit_dot);
76-
}
77-
7833
static int fix_unmerged_status(struct diff_filepair *p,
7934
struct update_callback_data *data)
8035
{
@@ -119,26 +74,10 @@ static void update_callback(struct diff_queue_struct *q,
11974
{
12075
int i;
12176
struct update_callback_data *data = cbdata;
122-
const char *implicit_dot = data->implicit_dot;
123-
size_t implicit_dot_len = data->implicit_dot_len;
12477

12578
for (i = 0; i < q->nr; i++) {
12679
struct diff_filepair *p = q->queue[i];
12780
const char *path = p->one->path;
128-
/*
129-
* Check if "git add -A" or "git add -u" was run from a
130-
* subdirectory with a modified file outside that directory,
131-
* and warn if so.
132-
*
133-
* "git add -u" will behave like "git add -u :/" instead of
134-
* "git add -u ." in the future. This warning prepares for
135-
* that change.
136-
*/
137-
if (implicit_dot &&
138-
strncmp_icase(path, implicit_dot, implicit_dot_len)) {
139-
warn_pathless_add();
140-
continue;
141-
}
14281
switch (fix_unmerged_status(p, data)) {
14382
default:
14483
die(_("unexpected diff status %c"), p->status);
@@ -194,9 +133,7 @@ int add_files_to_cache(const char *prefix,
194133
return !!data.add_errors;
195134
}
196135

197-
#define WARN_IMPLICIT_DOT (1u << 0)
198-
static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
199-
int prefix, unsigned flag)
136+
static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, int prefix)
200137
{
201138
char *seen;
202139
int i;
@@ -210,16 +147,6 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
210147
struct dir_entry *entry = *src++;
211148
if (dir_path_match(entry, pathspec, prefix, seen))
212149
*dst++ = entry;
213-
else if (flag & WARN_IMPLICIT_DOT)
214-
/*
215-
* "git add -A" was run from a subdirectory with a
216-
* new file outside that directory.
217-
*
218-
* "git add -A" will behave like "git add -A :/"
219-
* instead of "git add -A ." in the future.
220-
* Warn about the coming behavior change.
221-
*/
222-
warn_pathless_add();
223150
}
224151
dir->nr = dst - dir->entries;
225152
add_pathspec_matches_against_index(pathspec, seen);
@@ -411,7 +338,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
411338
int add_new_files;
412339
int require_pathspec;
413340
char *seen = NULL;
414-
int implicit_dot = 0;
415341
struct update_callback_data update_data;
416342

417343
git_config(add_config, NULL);
@@ -453,19 +379,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
453379

454380
if (!show_only && ignore_missing)
455381
die(_("Option --ignore-missing can only be used together with --dry-run"));
456-
if (addremove) {
457-
option_with_implicit_dot = "--all";
458-
short_option_with_implicit_dot = "-A";
459-
}
460-
if (take_worktree_changes) {
461-
option_with_implicit_dot = "--update";
462-
short_option_with_implicit_dot = "-u";
463-
}
464-
if (option_with_implicit_dot && !argc) {
465-
static const char *here[2] = { ".", NULL };
382+
383+
if ((addremove || take_worktree_changes) && !argc) {
384+
static const char *whole[2] = { ":/", NULL };
466385
argc = 1;
467-
argv = here;
468-
implicit_dot = 1;
386+
argv = whole;
469387
}
470388

471389
add_new_files = !take_worktree_changes && !refresh_only;
@@ -478,8 +396,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
478396
(intent_to_add ? ADD_CACHE_INTENT : 0) |
479397
(ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
480398
(!(addremove || take_worktree_changes)
481-
? ADD_CACHE_IGNORE_REMOVAL : 0)) |
482-
(implicit_dot ? ADD_CACHE_IMPLICIT_DOT : 0);
399+
? ADD_CACHE_IGNORE_REMOVAL : 0));
483400

484401
if (require_pathspec && argc == 0) {
485402
fprintf(stderr, _("Nothing specified, nothing added.\n"));
@@ -513,18 +430,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)
513430

514431
memset(&empty_pathspec, 0, sizeof(empty_pathspec));
515432
/* This picks up the paths that are not tracked */
516-
baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
433+
baselen = fill_directory(&dir, &pathspec);
517434
if (pathspec.nr)
518-
seen = prune_directory(&dir, &pathspec, baselen,
519-
implicit_dot ? WARN_IMPLICIT_DOT : 0);
435+
seen = prune_directory(&dir, &pathspec, baselen);
520436
}
521437

522438
if (refresh_only) {
523439
refresh(verbose, &pathspec);
524440
goto finish;
525441
}
526-
if (implicit_dot && prefix)
527-
refresh_cache(REFRESH_QUIET);
528442

529443
if (pathspec.nr) {
530444
int i;
@@ -564,18 +478,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
564478

565479
plug_bulk_checkin();
566480

567-
if ((flags & ADD_CACHE_IMPLICIT_DOT) && prefix) {
568-
/*
569-
* Check for modified files throughout the worktree so
570-
* update_callback has a chance to warn about changes
571-
* outside the cwd.
572-
*/
573-
update_data.implicit_dot = prefix;
574-
update_data.implicit_dot_len = strlen(prefix);
575-
free_pathspec(&pathspec);
576-
memset(&pathspec, 0, sizeof(pathspec));
577-
}
578-
update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
481+
update_data.flags = flags;
579482
update_files_in_cache(prefix, &pathspec, &update_data);
580483

581484
exit_status |= !!update_data.add_errors;

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ extern int remove_file_from_index(struct index_state *, const char *path);
483483
#define ADD_CACHE_IGNORE_ERRORS 4
484484
#define ADD_CACHE_IGNORE_REMOVAL 8
485485
#define ADD_CACHE_INTENT 16
486-
#define ADD_CACHE_IMPLICIT_DOT 32 /* internal to "git add -u/-A" */
487486
extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
488487
extern int add_file_to_index(struct index_state *, const char *path, int flags);
489488
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);

t/t2200-add-update.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,13 @@ test_expect_success 'change gets noticed' '
8080
8181
'
8282

83-
# Note that this is scheduled to change in Git 2.0, when
84-
# "git add -u" will become full-tree by default.
85-
test_expect_success 'non-limited update in subdir leaves root alone' '
83+
test_expect_success 'non-qualified update in subdir updates from the root' '
8684
(
8785
cd dir1 &&
8886
echo even more >>sub2 &&
8987
git add -u
9088
) &&
91-
cat >expect <<-\EOF &&
92-
check
93-
top
94-
EOF
89+
: >expect &&
9590
git diff-files --name-only >actual &&
9691
test_cmp expect actual
9792
'

0 commit comments

Comments
 (0)