Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sparse Index] Integrate git add with sparse-index #364

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -293,9 +293,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 @@ -311,13 +308,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 @@ -328,6 +318,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 @@ -567,7 +576,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