public void TestGetStatusChangedFilesFromString(string testName, string statusString) { // TODO produce a valid working directory var module = new GitModule(Path.GetTempPath()); var getAllChangedFilesOutputParser = new GetAllChangedFilesOutputParser(() => module); using (ApprovalResults.ForScenario(testName.Replace(' ', '_'))) { // git status --porcelain=2 --untracked-files=no -z var statuses = getAllChangedFilesOutputParser.Parse(statusString); Approvals.VerifyJson(JsonConvert.SerializeObject(statuses)); } }
public async Task <IEnumerable <AutoCompleteWord> > GetAutoCompleteWordsAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var autoCompleteWords = new HashSet <string>(); IGitModule module = GetModule(); ArgumentString cmd = GitCommandHelpers.GetAllChangedFilesCmd(true, UntrackedFilesMode.Default, noLocks: true); var output = await module.GitExecutable.GetOutputAsync(cmd).ConfigureAwait(false); IReadOnlyList <GitItemStatus> changedFiles = _getAllChangedFilesOutputParser.Parse(output); foreach (var file in changedFiles) { cancellationToken.ThrowIfCancellationRequested(); var regex = GetRegexForExtension(PathUtil.GetExtension(file.Name)); if (regex is not null) { // HACK: need to expose require methods at IGitModule level var text = await GetChangedFileTextAsync((GitModule)module, file); var matches = regex.Matches(text); foreach (Match match in matches) { // Skip first group since it always contains the entire matched string (regardless of capture groups) foreach (Group group in match.Groups.OfType <Group>().Skip(1)) { foreach (Capture capture in group.Captures) { autoCompleteWords.Add(capture.Value); } } } } autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.Name)); autoCompleteWords.Add(Path.GetFileName(file.Name)); if (!string.IsNullOrWhiteSpace(file.OldName)) { autoCompleteWords.Add(Path.GetFileNameWithoutExtension(file.OldName)); autoCompleteWords.Add(Path.GetFileName(file.OldName)); } } return(autoCompleteWords.Select(w => new AutoCompleteWord(w))); }