static IEnumerable <IFilePathFilter> ReadGitIgnoreExclusions(string rootDirectoryPath, IRemoteDevLogger logger) { // Always ignore .git folder yield return(new GlobFilePathFilter(".git")); yield return(new GlobFilePathFilter(".git/**")); // Ignore files from root gitignore var gitIgnorePath = Path.Combine(rootDirectoryPath, ".gitignore"); if (File.Exists(gitIgnorePath)) { logger.Log(LogLevel.INFO, $"Using the gitignore found in {gitIgnorePath}"); var filterCount = 0; using (var fs = File.OpenRead(gitIgnorePath)) using (var reader = new StreamReader(fs)) { while (!reader.EndOfStream) { var filter = GitIgnoreParser.ParseLine(reader.ReadLine()); if (filter != null) { filterCount++; yield return(filter); } } } logger.Log(LogLevel.INFO, $"Found {filterCount} blob filters in the gitignore file"); } else { logger.Log(LogLevel.WARN, "No .gitignore found in root directory. No file/folder changes will be ignored"); } }
public void GitIgnoreParser_Exclusion_Test(string pattern, string relativePath, bool isFile, bool expectMatch) => Assert.Equal(expectMatch, GitIgnoreParser.ParseLine(pattern).IsMatch(relativePath, isFile));
public void GitIgnoreParser_NullLine_Test(string inputLine) => Assert.Null(GitIgnoreParser.ParseLine(inputLine));