public async void TestSquashWriter() { string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); Directory.CreateDirectory(tempDirectory); GitProcessManager local = new GitProcessManager(tempDirectory, null); var result = await local.RunGit("init", CancellationToken.None); result.Success.Should().Be(true, "Must be able to init"); int numberCommits = 10; await this.GenerateCommits(numberCommits, tempDirectory, local, "master"); var branchManager = new BranchManager(tempDirectory, null); var commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.None, CancellationToken.None); IGitSquashWrapper squashWrapper = new GitSquashWrapper(tempDirectory, null); GitCommandResponse squashOutput = await squashWrapper.Squash(CancellationToken.None, "Bye Cruel World", commits.Last()); commits = await branchManager.GetCommitsForBranch(new GitBranch("master", false), 0, 0, GitLogOptions.None, CancellationToken.None); commits = commits.ToList(); commits.Count.Should().Be(2); commits[0].MessageLong.Should().BeEquivalentTo("Bye Cruel World"); }
public void TestCommentWriter() { string commentWritersName, rebaseWritersName; GitSquashWrapper.GetWritersName(out rebaseWritersName, out commentWritersName); File.Exists(commentWritersName).Should().BeTrue(); string validCommit = "This is awesome"; string fileName = Path.GetTempFileName(); File.WriteAllText(fileName, validCommit); string path = Path.GetTempFileName(); File.WriteAllText(path, @"This is my awesome commit. I don't want this."); Process process = new Process() { StartInfo = { CreateNoWindow = true, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, FileName = commentWritersName, Arguments = path, StandardErrorEncoding = Encoding.UTF8, StandardOutputEncoding = Encoding.UTF8 }, EnableRaisingEvents = true }; process.StartInfo.EnvironmentVariables.Add("COMMENT_FILE_NAME", fileName); process.Start(); StringBuilder output = new StringBuilder(); process.ErrorDataReceived += (sender, e) => output.Append(e.Data); process.OutputDataReceived += (sender, e) => output.Append(e.Data); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); string readAllText = File.ReadAllText(path); readAllText.Should().Be(validCommit); }
private object CreateGitWrapperService(IServiceContainer container, Type serviceType) { this.TraceWriteLine("Service Requested: " + serviceType.FullName); if (typeof(IGitSquashWrapper) == serviceType) { IVsOutputWindowPane outputWindow; var outWindow = GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow; var customGuid = new Guid("E53E7910-5B4F-4C5D-95BE-92BD439178E6"); outWindow.CreatePane(ref customGuid, "Git Squash", 1, 1); outWindow.GetPane(ref customGuid, out outputWindow); IGitSquashWrapper wrapper = null; if (this.gitService.ActiveRepositories.FirstOrDefault() != null) { string path = this.gitService.ActiveRepositories.FirstOrDefault()?.RepositoryPath; this.TraceWriteLine("Creating Wrapper service with path: " + path); wrapper = new GitSquashWrapper(path, new OutputWindowLogger(outputWindow)); } return(wrapper); } throw new ArgumentException(); }