42d906bec4
On a sparse checked out repository, `git grep` (without --cached) ends up searching the cache when an entry matches the search pathspec and has the SKIP_WORKTREE bit set. This is confusing both because the sparse paths are not expected to be in a working tree search (as they are not checked out), and because the output mixes working tree and cache results without distinguishing them. (Note that grep also resorts to the cache on working tree searches that include --assume-unchanged paths. But the whole point in that case is to assume that the contents of the index entry and the file are the same. This does not apply to the case of sparse paths, where the file isn't even expected to be present.) Fix that by teaching grep to honor the sparse-checkout rules for working tree searches. If the user wants to grep paths outside the current sparse-checkout definition, they may either update the sparsity rules to materialize the files, or use --cached to search all blobs registered in the index. Note: it might also be interesting to add a configuration option that allow users to search paths that are present despite having the SKIP_WORKTREE bit set, and/or to restrict searches in the index and past revisions too. These ideas are left as future improvements to avoid conflicting with other sparse-checkout topics currently in flight. Suggested-by: Elijah Newren <newren@gmail.com> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
153 lines
3.0 KiB
Bash
Executable File
153 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2008 Nguyễn Thái Ngọc Duy
|
|
#
|
|
|
|
test_description='skip-worktree bit test'
|
|
|
|
. ./test-lib.sh
|
|
|
|
cat >expect.full <<EOF
|
|
H 1
|
|
H 2
|
|
H init.t
|
|
H sub/1
|
|
H sub/2
|
|
EOF
|
|
|
|
cat >expect.skip <<EOF
|
|
S 1
|
|
H 2
|
|
H init.t
|
|
S sub/1
|
|
H sub/2
|
|
EOF
|
|
|
|
setup_absent() {
|
|
test -f 1 && rm 1
|
|
git update-index --remove 1 &&
|
|
git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
|
|
git update-index --skip-worktree 1
|
|
}
|
|
|
|
test_absent() {
|
|
echo "100644 $EMPTY_BLOB 0 1" > expected &&
|
|
git ls-files --stage 1 > result &&
|
|
test_cmp expected result &&
|
|
test ! -f 1
|
|
}
|
|
|
|
setup_dirty() {
|
|
git update-index --force-remove 1 &&
|
|
echo dirty > 1 &&
|
|
git update-index --add --cacheinfo 100644 $EMPTY_BLOB 1 &&
|
|
git update-index --skip-worktree 1
|
|
}
|
|
|
|
test_dirty() {
|
|
echo "100644 $EMPTY_BLOB 0 1" > expected &&
|
|
git ls-files --stage 1 > result &&
|
|
test_cmp expected result &&
|
|
echo dirty > expected
|
|
test_cmp expected 1
|
|
}
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit init &&
|
|
mkdir sub &&
|
|
touch ./1 ./2 sub/1 sub/2 &&
|
|
git add 1 2 sub/1 sub/2 &&
|
|
git update-index --skip-worktree 1 sub/1 &&
|
|
git ls-files -t > result &&
|
|
test_cmp expect.skip result
|
|
'
|
|
|
|
test_expect_success 'update-index' '
|
|
setup_absent &&
|
|
git update-index 1 &&
|
|
test_absent
|
|
'
|
|
|
|
test_expect_success 'update-index' '
|
|
setup_dirty &&
|
|
git update-index 1 &&
|
|
test_dirty
|
|
'
|
|
|
|
test_expect_success 'update-index --remove' '
|
|
setup_absent &&
|
|
git update-index --remove 1 &&
|
|
test -z "$(git ls-files 1)" &&
|
|
test ! -f 1
|
|
'
|
|
|
|
test_expect_success 'update-index --remove' '
|
|
setup_dirty &&
|
|
git update-index --remove 1 &&
|
|
test -z "$(git ls-files 1)" &&
|
|
echo dirty > expected &&
|
|
test_cmp expected 1
|
|
'
|
|
|
|
test_expect_success 'ls-files --deleted' '
|
|
setup_absent &&
|
|
test -z "$(git ls-files -d)"
|
|
'
|
|
|
|
test_expect_success 'ls-files --deleted' '
|
|
setup_dirty &&
|
|
test -z "$(git ls-files -d)"
|
|
'
|
|
|
|
test_expect_success 'ls-files --modified' '
|
|
setup_absent &&
|
|
test -z "$(git ls-files -m)"
|
|
'
|
|
|
|
test_expect_success 'ls-files --modified' '
|
|
setup_dirty &&
|
|
test -z "$(git ls-files -m)"
|
|
'
|
|
|
|
echo ":000000 100644 $ZERO_OID $EMPTY_BLOB A 1" > expected
|
|
test_expect_success 'diff-index does not examine skip-worktree absent entries' '
|
|
setup_absent &&
|
|
git diff-index HEAD -- 1 > result &&
|
|
test_cmp expected result
|
|
'
|
|
|
|
test_expect_success 'diff-index does not examine skip-worktree dirty entries' '
|
|
setup_dirty &&
|
|
git diff-index HEAD -- 1 > result &&
|
|
test_cmp expected result
|
|
'
|
|
|
|
test_expect_success 'diff-files does not examine skip-worktree absent entries' '
|
|
setup_absent &&
|
|
test -z "$(git diff-files -- one)"
|
|
'
|
|
|
|
test_expect_success 'diff-files does not examine skip-worktree dirty entries' '
|
|
setup_dirty &&
|
|
test -z "$(git diff-files -- one)"
|
|
'
|
|
|
|
test_expect_success 'git-rm succeeds on skip-worktree absent entries' '
|
|
setup_absent &&
|
|
git rm 1
|
|
'
|
|
|
|
test_expect_success 'commit on skip-worktree absent entries' '
|
|
git reset &&
|
|
setup_absent &&
|
|
test_must_fail git commit -m null 1
|
|
'
|
|
|
|
test_expect_success 'commit on skip-worktree dirty entries' '
|
|
git reset &&
|
|
setup_dirty &&
|
|
test_must_fail git commit -m null 1
|
|
'
|
|
|
|
test_done
|