зеркало из https://github.com/microsoft/git.git
Merge branch 'cp/add-u-pathspec'
* cp/add-u-pathspec: test for add with non-existent pathspec git add -u: die on unmatched pathspec
This commit is contained in:
Коммит
e25ccff140
|
@ -117,7 +117,19 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
|
static char *find_used_pathspec(const char **pathspec)
|
||||||
|
{
|
||||||
|
char *seen;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; pathspec[i]; i++)
|
||||||
|
; /* just counting */
|
||||||
|
seen = xcalloc(i, 1);
|
||||||
|
fill_pathspec_matches(pathspec, seen, i);
|
||||||
|
return seen;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
|
||||||
{
|
{
|
||||||
char *seen;
|
char *seen;
|
||||||
int i, specs;
|
int i, specs;
|
||||||
|
@ -137,13 +149,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
|
||||||
}
|
}
|
||||||
dir->nr = dst - dir->entries;
|
dir->nr = dst - dir->entries;
|
||||||
fill_pathspec_matches(pathspec, seen, specs);
|
fill_pathspec_matches(pathspec, seen, specs);
|
||||||
|
return seen;
|
||||||
for (i = 0; i < specs; i++) {
|
|
||||||
if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i]))
|
|
||||||
die("pathspec '%s' did not match any files",
|
|
||||||
pathspec[i]);
|
|
||||||
}
|
|
||||||
free(seen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void treat_gitlinks(const char **pathspec)
|
static void treat_gitlinks(const char **pathspec)
|
||||||
|
@ -359,6 +365,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
int flags;
|
int flags;
|
||||||
int add_new_files;
|
int add_new_files;
|
||||||
int require_pathspec;
|
int require_pathspec;
|
||||||
|
char *seen = NULL;
|
||||||
|
|
||||||
git_config(add_config, NULL);
|
git_config(add_config, NULL);
|
||||||
|
|
||||||
|
@ -418,7 +425,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
/* This picks up the paths that are not tracked */
|
/* This picks up the paths that are not tracked */
|
||||||
baselen = fill_directory(&dir, pathspec);
|
baselen = fill_directory(&dir, pathspec);
|
||||||
if (pathspec)
|
if (pathspec)
|
||||||
prune_directory(&dir, pathspec, baselen);
|
seen = prune_directory(&dir, pathspec, baselen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refresh_only) {
|
if (refresh_only) {
|
||||||
|
@ -426,6 +433,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pathspec) {
|
||||||
|
int i;
|
||||||
|
if (!seen)
|
||||||
|
seen = find_used_pathspec(pathspec);
|
||||||
|
for (i = 0; pathspec[i]; i++) {
|
||||||
|
if (!seen[i] && pathspec[i][0]
|
||||||
|
&& !file_exists(pathspec[i]))
|
||||||
|
die("pathspec '%s' did not match any files",
|
||||||
|
pathspec[i]);
|
||||||
|
}
|
||||||
|
free(seen);
|
||||||
|
}
|
||||||
|
|
||||||
exit_status |= add_files_to_cache(prefix, pathspec, flags);
|
exit_status |= add_files_to_cache(prefix, pathspec, flags);
|
||||||
|
|
||||||
if (add_new_files)
|
if (add_new_files)
|
||||||
|
|
|
@ -176,4 +176,9 @@ test_expect_success 'add -u resolves unmerged paths' '
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '"add -u non-existent" should fail' '
|
||||||
|
test_must_fail git add -u non-existent &&
|
||||||
|
! (git ls-files | grep "non-existent")
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
|
@ -255,4 +255,9 @@ test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
|
||||||
git add track-this
|
git add track-this
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '"add non-existent" should fail' '
|
||||||
|
test_must_fail git add non-existent &&
|
||||||
|
! (git ls-files | grep "non-existent")
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Загрузка…
Ссылка в новой задаче