Skip to content

Commit

Permalink
Merge sparse-aware 'git add' into vfs-2.32.0
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Jun 7, 2021
2 parents 1eb8541 + 13c8719 commit 04ad40b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);

/*
Expand Down
2 changes: 0 additions & 2 deletions pathspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
num_unmatched++;
if (!num_unmatched)
return;
/* TODO: audit for interaction with sparse-index. */
ensure_full_index(istate);
for (i = 0; i < istate->cache_nr; i++) {
const struct cache_entry *ce = istate->cache[i];
if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce))
Expand Down
38 changes: 27 additions & 11 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ test_expect_success 'commit including unstaged changes' '
test_expect_success 'status/add: outside sparse cone' '
init_repos &&
# adding a "missing" file outside the cone should fail
test_sparse_match test_must_fail git add folder1/a &&
# folder1 is at HEAD, but outside the sparse cone
run_on_sparse mkdir folder1 &&
cp initial-repo/folder1/a sparse-checkout/folder1/a &&
Expand All @@ -308,13 +305,6 @@ test_expect_success 'status/add: outside sparse cone' '
test_sparse_match git status --porcelain=v2 &&
# This "git add folder1/a" fails with a warning
# in the sparse repos, differing from the full
# repo. This is intentional.
test_sparse_match test_must_fail git add folder1/a &&
test_sparse_match test_must_fail git add --refresh folder1/a &&
test_all_match git status --porcelain=v2 &&
test_all_match git add . &&
test_all_match git status --porcelain=v2 &&
test_all_match git commit -m folder1/new &&
Expand All @@ -325,6 +315,25 @@ test_expect_success 'status/add: outside sparse cone' '
test_all_match git commit -m folder1/newer
'

test_expect_failure 'add: pathspec within sparse directory' '
init_repos &&
run_on_sparse mkdir folder1 &&
run_on_sparse ../edit-contents folder1/a &&
run_on_all ../edit-contents folder1/new &&
# This "git add folder1/a" fails with a warning
# in the sparse repos, differing from the full
# repo. This is intentional.
#
# However, in the sparse-index, folder1/a does not
# match any cache entry and fails with a different
# error message. This needs work.
test_sparse_match test_must_fail git add folder1/a &&
test_sparse_match test_must_fail git add --refresh folder1/a &&
test_all_match git status --porcelain=v2
'

test_expect_success 'checkout and reset --hard' '
init_repos &&
Expand Down Expand Up @@ -564,7 +573,14 @@ test_expect_success 'sparse-index is not expanded' '
git -C sparse-index reset --hard &&
ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
git -C sparse-index reset --hard &&
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
echo >>sparse-index/README.md &&
ensure_not_expanded add -A &&
echo >>sparse-index/extra.txt &&
ensure_not_expanded add extra.txt &&
echo >>sparse-index/untracked.txt &&
ensure_not_expanded add .
'

test_expect_success 'reset mixed and checkout orphan' '
Expand Down

0 comments on commit 04ad40b

Please sign in to comment.