Repository: microsoft/vscode (TypeScript)
Date: 2023-05-24 21:04:33+00:00
Task type: Bug Fix

Issue:
.gitignore files don't take effect in Search if there is no .git folder 
Type: <b>Bug</b>

Steps to reproduce:
1. Create the following files in a folder and open it with Code:
   ```
   something/
     something irrelevant.txt
     something/
       also something irrelevant.txt
   .gitignore
   irrelevant.md
   abc.txt
   ```

   Fill each file with the text `Something`, except for .gitignore which should be:
   ```ignore
   /something
   *.md
   ```
2. Open the search panel from the activity bar, and search for "Some".

Expected behavior: All files (including .gitignore) except for those with "irrelevant" in its name are displayed in the results.

Actual behavior: Every file is shown.

Does this happen when all extensions are disabled?: Yes

VS Code version: Code - Insiders 1.79.0-insider (2d416df5f00253f5ebd60d2f08508a440747fd8d, 2023-05-19T05:25:00.632Z)
OS version: Windows_NT x64 10.0.19042
Modes:


<!-- generated by issue reporter -->


Issue discussion:
When you do this, do you have the ignored files open in the editor?
The same seems to happen no matter what files are opened in the editor.

Tested with 1.79.0-insider (6d3fedb7c2cf965915c785dc07701eb978947506, 2023-05-19T20:39:14.598Z)
Also, I verified that `search.useIgnoreFiles` is `true`.
That's so strange. I can't seem to repro this. Do you have any other search related settings that aren't default? Can you show a screen recording?

Solution patch:
diff --git a/src/vs/workbench/services/search/node/ripgrepFileSearch.ts b/src/vs/workbench/services/search/node/ripgrepFileSearch.ts
--- a/src/vs/workbench/services/search/node/ripgrepFileSearch.ts
+++ b/src/vs/workbench/services/search/node/ripgrepFileSearch.ts
@@ -30,7 +30,7 @@ export function spawnRipgrepCmd(config: IFileQuery, folderQuery: IFolderQuery, i
 }
 
 function getRgArgs(config: IFileQuery, folderQuery: IFolderQuery, includePattern?: glob.IExpression, excludePattern?: glob.IExpression) {
-	const args = ['--files', '--hidden', '--case-sensitive'];
+	const args = ['--files', '--hidden', '--case-sensitive', '--no-require-git'];
 
 	// includePattern can't have siblingClauses
 	foldersToIncludeGlobs([folderQuery], includePattern, false).forEach(globArg => {
diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
--- a/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
+++ b/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
@@ -370,7 +370,7 @@ function getNumLinesAndLastNewlineLength(text: string): { numLines: number; last
 
 // exported for testing
 export function getRgArgs(query: TextSearchQuery, options: TextSearchOptions): string[] {
-	const args = ['--hidden'];
+	const args = ['--hidden', '--no-require-git'];
 	args.push(query.isCaseSensitive ? '--case-sensitive' : '--ignore-case');
 
 	const { doubleStarIncludes, otherIncludes } = groupBy(


Test patch:
diff --git a/src/vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test.ts b/src/vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test.ts
--- a/src/vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test.ts
+++ b/src/vs/workbench/services/search/test/node/ripgrepTextSearchEngineUtils.test.ts
@@ -317,6 +317,7 @@ suite('RipgrepTextSearchEngine', () => {
 				};
 				const expected = [
 					'--hidden',
+					'--no-require-git',
 					'--ignore-case',
 					...expectedFromIncludes,
 					'--no-ignore',