public DiffResult ScanDiff() { var diffResult = new DiffResult() { ChangedFiles = new Collection <string>(), TestsChanged = false }; // A git repository has been detected, calculate the diff to filter var commit = _gitInfoProvider.DetermineCommit(); if (commit == null) { throw new Stryker.Core.Exceptions.StrykerInputException("Could not determine a commit to check for diff. Please check you have provided the correct value for --git-source"); } foreach (var patchChanges in _gitInfoProvider.Repository.Diff.Compare <Patch>(commit.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory)) { string diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_gitInfoProvider.RepositoryPath, patchChanges.Path)); diffResult.ChangedFiles.Add(diffPath); if (diffPath.StartsWith(_options.BasePath) && diffPath.EndsWith(".cs")) { diffResult.TestsChanged = true; } } return(diffResult); }
private void RemoveFilteredOutFiles(DiffResult diffResult) { foreach (FilePattern filePattern in _options.DiffIgnoreFiles) { diffResult.ChangedSourceFiles = diffResult.ChangedSourceFiles.Where(diffResultFile => !filePattern.Glob.IsMatch(diffResultFile)).ToList(); diffResult.ChangedTestFiles = diffResult.ChangedTestFiles.Where(diffResultFile => !filePattern.Glob.IsMatch(diffResultFile)).ToList(); } }
public DiffResult ScanDiff() { var diffResult = new DiffResult() { ChangedSourceFiles = new Collection <string>(), ChangedTestFiles = new Collection <string>() }; // A git repository has been detected, calculate the diff to filter var repository = _gitInfoProvider.Repository; var commit = _gitInfoProvider.DetermineCommit(); if (commit == null) { throw new StrykerInputException("Could not determine a commit to check for diff. Please check you have provided the correct value for --git-source"); } foreach (var patchChanges in repository.Diff.Compare <Patch>(commit.Tree, DiffTargets.WorkingDirectory)) { string diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(_gitInfoProvider.RepositoryPath, patchChanges.Path)); if (diffPath.EndsWith("stryker-config.json")) { continue; } var fullName = _options.BasePath.EndsWith(Path.DirectorySeparatorChar) ? _options.BasePath : _options.BasePath + Path.DirectorySeparatorChar; if (diffPath.StartsWith(fullName)) { diffResult.ChangedTestFiles.Add(diffPath); } else { diffResult.ChangedSourceFiles.Add(diffPath); } } RemoveFilteredOutFiles(diffResult); return(diffResult); }
public DiffResult ScanDiff() { string repositoryPath = Repository.Discover(_options.BasePath)?.Split(".git")[0]; if (string.IsNullOrEmpty(repositoryPath)) { throw new StrykerInputException("Could not locate git repository. Unable to determine git diff to filter mutants. Did you run inside a git repo? If not please disable the --diff feature."); } var diffResult = new DiffResult() { ChangedFiles = new Collection <string>(), TestsChanged = false }; // A git repository has been detected, calculate the diff to filter using (var repository = new Repository(repositoryPath)) { var sourceBranch = repository.Branches[_options.GitSource]; if (sourceBranch == null) { throw new StrykerInputException("Git source branch does not exist. Please set another source branch or remove the --git-source option."); } foreach (var treeChanges in repository.Diff.Compare <TreeChanges>(sourceBranch.Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory)) { string diffPath = FilePathUtils.NormalizePathSeparators(Path.Combine(repositoryPath, treeChanges.Path)); diffResult.ChangedFiles.Add(diffPath); if (diffPath.StartsWith(_options.BasePath)) { diffResult.TestsChanged = true; } } } return(diffResult); }