Ignore anything starting with ".git"

Fixes #29782
This commit is contained in:
Sheetal Nandi 2019-03-06 15:00:26 -08:00
parent 79a1f29727
commit ec2ee9ff3a
5 changed files with 29 additions and 10 deletions

View File

@ -71,8 +71,8 @@ namespace ts {
nonRecursive?: boolean;
}
export function isPathInNodeModulesStartingWithDot(path: Path) {
return stringContains(path, "/node_modules/.");
export function isPathIgnored(path: Path) {
return some(ignoredPaths, searchPath => stringContains(path, searchPath));
}
export const maxNumberOfFilesToIterateForInvalidation = 256;
@ -696,7 +696,7 @@ namespace ts {
}
else {
// If something to do with folder/file starting with "." in node_modules folder, skip it
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return false;
if (isPathIgnored(fileOrDirectoryPath)) return false;
// Some file or directory in the watching directory is created
// Return early if it does not have any of the watching extension or not the custom failed lookup path

View File

@ -326,6 +326,9 @@ namespace ts {
: FileWatcherEventKind.Changed;
}
/*@internal*/
export const ignoredPaths = ["/node_modules/.", "/.git"];
/*@internal*/
export interface RecursiveDirectoryWatcherHost {
watchDirectory: HostWatchDirectory;
@ -371,7 +374,7 @@ namespace ts {
else {
directoryWatcher = {
watcher: host.watchDirectory(dirName, fileName => {
if (isInNodeModulesStartingWithDot(fileName)) return;
if (isIgnoredPath(fileName)) return;
// Call the actual callback
callbackCache.forEach((callbacks, rootDirName) => {
@ -428,7 +431,7 @@ namespace ts {
const childFullName = getNormalizedAbsolutePath(child, parentDir);
// Filter our the symbolic link directories since those arent included in recursive watch
// which is same behaviour when recursive: true is passed to fs.watch
return !isInNodeModulesStartingWithDot(childFullName) && filePathComparer(childFullName, normalizePath(host.realpath(childFullName))) === Comparison.EqualTo ? childFullName : undefined;
return !isIgnoredPath(childFullName) && filePathComparer(childFullName, normalizePath(host.realpath(childFullName))) === Comparison.EqualTo ? childFullName : undefined;
}) : emptyArray,
existingChildWatches,
(child, childWatcher) => filePathComparer(child, childWatcher.dirName),
@ -455,8 +458,8 @@ namespace ts {
}
}
function isInNodeModulesStartingWithDot(path: string) {
return isInPath(path, "/node_modules/.");
function isIgnoredPath(path: string) {
return some(ignoredPaths, searchPath => isInPath(path, searchPath));
}
function isInPath(path: string, searchPath: string) {

View File

@ -987,7 +987,7 @@ namespace ts {
}
nextSourceFileVersion(fileOrDirectoryPath);
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
if (isPathIgnored(fileOrDirectoryPath)) return;
// If the the added or created file or directory is not supported file name, ignore the file
// But when watched directory is added/removed, we need to reload the file list

View File

@ -1002,7 +1002,7 @@ namespace ts.server {
fileOrDirectory => {
const fileOrDirectoryPath = this.toPath(fileOrDirectory);
project.getCachedDirectoryStructureHost().addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
if (isPathIgnored(fileOrDirectoryPath)) return;
const configFilename = project.getConfigFilePath();
// If the the added or created file or directory is not supported file name, ignore the file
@ -2071,7 +2071,7 @@ namespace ts.server {
watchDir,
(fileOrDirectory) => {
const fileOrDirectoryPath = this.toPath(fileOrDirectory);
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
if (isPathIgnored(fileOrDirectoryPath)) return;
// Has extension
Debug.assert(result.refCount > 0);

View File

@ -183,6 +183,22 @@ namespace ts.projectSystem {
host.checkTimeoutQueueLength(0);
verifyProject();
const gitIgnoredFileFromIgnoreDirectory: File = {
path: `${projectFolder}/.git/someFile.d.ts`,
content: ""
};
host.ensureFileOrFolder(gitIgnoredFileFromIgnoreDirectory);
host.checkTimeoutQueueLength(0);
verifyProject();
const gitIgnoredFile: File = {
path: `${projectFolder}/.gitCache.d.ts`,
content: ""
};
host.ensureFileOrFolder(gitIgnoredFile);
host.checkTimeoutQueueLength(0);
verifyProject();
function verifyProject() {
checkWatchedDirectories(host, emptyArray, /*recursive*/ true);
checkWatchedFilesDetailed(host, expectedWatchedFiles);