Skip to content

Commit 76066a7

Browse files
committed
add: ignore outside the sparse-checkout in refresh()
Since b243012 (refresh_index(): add flag to ignore SKIP_WORKTREE entries, 2021-04-08), 'git add --refresh <path>' will output a warning message when the path is outside the sparse-checkout definition. The implementation of this warning happened in parallel with the sparse-index work to add ensure_full_index() calls throughout the codebase. Update this loop to have the proper logic that checks to see if the pathspec is outside the sparse-checkout definition. This avoids the need to expand the sparse directory entry and determine if the path is tracked, untracked, or ignored. We simply avoid updating the stat() information because there isn't even an entry that matches the path! Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 89ec6a7 commit 76066a7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

builtin/add.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,21 @@ static int refresh(int verbose, const struct pathspec *pathspec)
192192
struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
193193
int flags = REFRESH_IGNORE_SKIP_WORKTREE |
194194
(verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
195+
struct pattern_list pl = { 0 };
196+
int sparse_checkout_enabled = !get_sparse_checkout_patterns(&pl);
195197

196198
seen = xcalloc(pathspec->nr, 1);
197199
refresh_index(&the_index, flags, pathspec, seen,
198200
_("Unstaged changes after refreshing the index:"));
199201
for (i = 0; i < pathspec->nr; i++) {
200202
if (!seen[i]) {
201-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen)) {
203+
const char *path = pathspec->items[i].original;
204+
int dtype = DT_REG;
205+
206+
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
207+
(sparse_checkout_enabled &&
208+
!path_matches_pattern_list(path, strlen(path), NULL,
209+
&dtype, &pl, &the_index))) {
202210
string_list_append(&only_match_skip_worktree,
203211
pathspec->items[i].original);
204212
} else {

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ test_expect_success 'status/add: outside sparse cone' '
347347
test_all_match git commit -m folder1/newer
348348
'
349349

350-
test_expect_failure 'add: pathspec within sparse directory' '
350+
test_expect_success 'add: pathspec within sparse directory' '
351351
init_repos &&
352352
353353
run_on_sparse mkdir folder1 &&
@@ -357,10 +357,6 @@ test_expect_failure 'add: pathspec within sparse directory' '
357357
# This "git add folder1/a" fails with a warning
358358
# in the sparse repos, differing from the full
359359
# repo. This is intentional.
360-
#
361-
# However, in the sparse-index, folder1/a does not
362-
# match any cache entry and fails with a different
363-
# error message. This needs work.
364360
test_sparse_match test_must_fail git add folder1/a &&
365361
test_sparse_match test_must_fail git add --refresh folder1/a &&
366362
test_all_match git status --porcelain=v2

0 commit comments

Comments
 (0)