mirror of
https://github.com/git/git
synced 2024-09-13 13:24:41 +00:00
Merge branch 'nd/ita-cleanup' into maint
Git does not know what the contents in the index should be for a path added with "git add -N" yet, so "git grep --cached" should not show hits (or show lack of hits, with -L) in such a path, but that logic does not apply to "git grep", i.e. searching in the working tree files. But we did so by mistake, which has been corrected. * nd/ita-cleanup: grep: fix grepping for "intent to add" files t7810-grep.sh: fix a whitespace inconsistency t7810-grep.sh: fix duplicated test name
This commit is contained in:
commit
c12c71fabb
|
@ -386,7 +386,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
|
||||||
|
|
||||||
for (nr = 0; nr < active_nr; nr++) {
|
for (nr = 0; nr < active_nr; nr++) {
|
||||||
const struct cache_entry *ce = active_cache[nr];
|
const struct cache_entry *ce = active_cache[nr];
|
||||||
if (!S_ISREG(ce->ce_mode) || ce_intent_to_add(ce))
|
if (!S_ISREG(ce->ce_mode))
|
||||||
continue;
|
continue;
|
||||||
if (!ce_path_match(ce, pathspec, NULL))
|
if (!ce_path_match(ce, pathspec, NULL))
|
||||||
continue;
|
continue;
|
||||||
|
@ -396,7 +396,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
|
||||||
* cache version instead
|
* cache version instead
|
||||||
*/
|
*/
|
||||||
if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
|
if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
|
||||||
if (ce_stage(ce))
|
if (ce_stage(ce) || ce_intent_to_add(ce))
|
||||||
continue;
|
continue;
|
||||||
hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);
|
hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1377,4 +1377,62 @@ test_expect_success 'grep --color -e A --and -e B -p with context' '
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep can find things only in the work tree' '
|
||||||
|
: >work-tree-only &&
|
||||||
|
git add work-tree-only &&
|
||||||
|
test_when_finished "git rm -f work-tree-only" &&
|
||||||
|
echo "find in work tree" >work-tree-only &&
|
||||||
|
git grep --quiet "find in work tree" &&
|
||||||
|
test_must_fail git grep --quiet --cached "find in work tree" &&
|
||||||
|
test_must_fail git grep --quiet "find in work tree" HEAD
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep can find things only in the work tree (i-t-a)' '
|
||||||
|
echo "intend to add this" >intend-to-add &&
|
||||||
|
git add -N intend-to-add &&
|
||||||
|
test_when_finished "git rm -f intend-to-add" &&
|
||||||
|
git grep --quiet "intend to add this" &&
|
||||||
|
test_must_fail git grep --quiet --cached "intend to add this" &&
|
||||||
|
test_must_fail git grep --quiet "intend to add this" HEAD
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep does not search work tree with assume unchanged' '
|
||||||
|
echo "intend to add this" >intend-to-add &&
|
||||||
|
git add -N intend-to-add &&
|
||||||
|
git update-index --assume-unchanged intend-to-add &&
|
||||||
|
test_when_finished "git rm -f intend-to-add" &&
|
||||||
|
test_must_fail git grep --quiet "intend to add this" &&
|
||||||
|
test_must_fail git grep --quiet --cached "intend to add this" &&
|
||||||
|
test_must_fail git grep --quiet "intend to add this" HEAD
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep can find things only in the index' '
|
||||||
|
echo "only in the index" >cache-this &&
|
||||||
|
git add cache-this &&
|
||||||
|
rm cache-this &&
|
||||||
|
test_when_finished "git rm --cached cache-this" &&
|
||||||
|
test_must_fail git grep --quiet "only in the index" &&
|
||||||
|
git grep --quiet --cached "only in the index" &&
|
||||||
|
test_must_fail git grep --quiet "only in the index" HEAD
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep does not report i-t-a with -L --cached' '
|
||||||
|
echo "intend to add this" >intend-to-add &&
|
||||||
|
git add -N intend-to-add &&
|
||||||
|
test_when_finished "git rm -f intend-to-add" &&
|
||||||
|
git ls-files | grep -v "^intend-to-add\$" >expected &&
|
||||||
|
git grep -L --cached "nonexistent_string" >actual &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '
|
||||||
|
echo "intend to add this" >intend-to-add-assume-unchanged &&
|
||||||
|
git add -N intend-to-add-assume-unchanged &&
|
||||||
|
test_when_finished "git rm -f intend-to-add-assume-unchanged" &&
|
||||||
|
git update-index --assume-unchanged intend-to-add-assume-unchanged &&
|
||||||
|
git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected &&
|
||||||
|
git grep -L "nonexistent_string" >actual &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue