зеркало из https://github.com/microsoft/git.git
rm: add --sparse option
As we did previously in 'git add', add a '--sparse' option to 'git rm' that allows modifying paths outside of the sparse-checkout definition. The existing checks in 'git rm' are restricted to tracked files that have the SKIP_WORKTREE bit in the current index. Future changes will cause 'git rm' to reject removing paths outside of the sparse-checkout definition, even if they are untracked or do not have the SKIP_WORKTREE bit. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
61d450f049
Коммит
f9786f9b85
|
@ -72,6 +72,12 @@ For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
|
||||||
--ignore-unmatch::
|
--ignore-unmatch::
|
||||||
Exit with a zero status even if no files matched.
|
Exit with a zero status even if no files matched.
|
||||||
|
|
||||||
|
--sparse::
|
||||||
|
Allow updating index entries outside of the sparse-checkout cone.
|
||||||
|
Normally, `git rm` refuses to update index entries whose paths do
|
||||||
|
not fit within the sparse-checkout cone. See
|
||||||
|
linkgit:git-sparse-checkout[1] for more.
|
||||||
|
|
||||||
-q::
|
-q::
|
||||||
--quiet::
|
--quiet::
|
||||||
`git rm` normally outputs one line (in the form of an `rm` command)
|
`git rm` normally outputs one line (in the form of an `rm` command)
|
||||||
|
|
|
@ -237,6 +237,7 @@ static int check_local_mod(struct object_id *head, int index_only)
|
||||||
|
|
||||||
static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
|
static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
|
||||||
static int ignore_unmatch = 0, pathspec_file_nul;
|
static int ignore_unmatch = 0, pathspec_file_nul;
|
||||||
|
static int include_sparse;
|
||||||
static char *pathspec_from_file;
|
static char *pathspec_from_file;
|
||||||
|
|
||||||
static struct option builtin_rm_options[] = {
|
static struct option builtin_rm_options[] = {
|
||||||
|
@ -247,6 +248,7 @@ static struct option builtin_rm_options[] = {
|
||||||
OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")),
|
OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")),
|
||||||
OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch,
|
OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch,
|
||||||
N_("exit with a zero status even if nothing matched")),
|
N_("exit with a zero status even if nothing matched")),
|
||||||
|
OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
|
||||||
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
|
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
|
||||||
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
|
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
|
@ -298,7 +300,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
|
||||||
ensure_full_index(&the_index);
|
ensure_full_index(&the_index);
|
||||||
for (i = 0; i < active_nr; i++) {
|
for (i = 0; i < active_nr; i++) {
|
||||||
const struct cache_entry *ce = active_cache[i];
|
const struct cache_entry *ce = active_cache[i];
|
||||||
if (ce_skip_worktree(ce))
|
|
||||||
|
if (!include_sparse && ce_skip_worktree(ce))
|
||||||
continue;
|
continue;
|
||||||
if (!ce_path_match(&the_index, ce, &pathspec, seen))
|
if (!ce_path_match(&the_index, ce, &pathspec, seen))
|
||||||
continue;
|
continue;
|
||||||
|
@ -322,7 +325,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
|
||||||
seen_any = 1;
|
seen_any = 1;
|
||||||
else if (ignore_unmatch)
|
else if (ignore_unmatch)
|
||||||
continue;
|
continue;
|
||||||
else if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen))
|
else if (!include_sparse &&
|
||||||
|
matches_skip_worktree(&pathspec, i, &skip_worktree_seen))
|
||||||
string_list_append(&only_match_skip_worktree, original);
|
string_list_append(&only_match_skip_worktree, original);
|
||||||
else
|
else
|
||||||
die(_("pathspec '%s' did not match any files"), original);
|
die(_("pathspec '%s' did not match any files"), original);
|
||||||
|
|
|
@ -43,6 +43,18 @@ test_expect_success 'recursive rm does not remove sparse entries' '
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'recursive rm --sparse removes sparse entries' '
|
||||||
|
git reset --hard &&
|
||||||
|
git sparse-checkout set "sub/dir" &&
|
||||||
|
git rm --sparse -r sub &&
|
||||||
|
git status --porcelain -uno >actual &&
|
||||||
|
cat >expected <<-\EOF &&
|
||||||
|
D sub/d
|
||||||
|
D sub/dir/e
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'rm obeys advice.updateSparsePath' '
|
test_expect_success 'rm obeys advice.updateSparsePath' '
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
git sparse-checkout set a &&
|
git sparse-checkout set a &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче