private async Task <GitCommandResponse> PerformRebase(CancellationToken token) { var rebaseOutput = await this.SquashWrapper.Rebase(token, this.SelectedRebaseBranch); GitCommandResponse forcePushOutput = null; if (this.DoForcePush) { forcePushOutput = await this.SquashWrapper.PushForce(token); if (forcePushOutput.Success == false || token.IsCancellationRequested) { return(forcePushOutput); } } StringBuilder sb = new StringBuilder(); if (rebaseOutput != null && rebaseOutput.Success) { sb.AppendLine(rebaseOutput.OutputMessage); } if (forcePushOutput != null && forcePushOutput.Success) { sb.AppendLine(forcePushOutput.OutputMessage); } return(new GitCommandResponse(true, sb.ToString(), null, 0)); }
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"); }
private async Task <GitCommandResponse> PerformSquash(CancellationToken token) { Settings.Default.PreviousCommitMessage = this.CommitMessage; Settings.Default.Save(); GitCommandResponse squashOutput = await this.SquashWrapper.Squash(token, this.CommitMessage, this.SelectedCommit); if (squashOutput.Success == false || token.IsCancellationRequested) { return(squashOutput); } GitCommandResponse forcePushOutput = null; if (this.DoForcePush) { forcePushOutput = await this.PerformPushForce(token); } GitCommandResponse rebaseOutput = null; if (this.ApplyRebase) { rebaseOutput = await this.SquashWrapper.Rebase(token, this.SelectedRebaseBranch); if (rebaseOutput.Success == false || token.IsCancellationRequested) { return(rebaseOutput); } } if (this.ApplyRebase && this.DoForcePush) { forcePushOutput = await this.PerformPushForce(token); } StringBuilder sb = new StringBuilder(); if (squashOutput.Success) { sb.AppendLine(squashOutput.OutputMessage); } if (forcePushOutput != null && forcePushOutput.Success) { sb.AppendLine(forcePushOutput.OutputMessage); } if (rebaseOutput != null && rebaseOutput.Success) { sb.AppendLine(rebaseOutput.OutputMessage); } return(new GitCommandResponse(true, sb.ToString(), null, 0)); }
private async Task <GitCommandResponse> PerformFetchOrigin(CancellationToken token) { if (token.IsCancellationRequested) { return(null); } GitCommandResponse result = await this.SquashWrapper.FetchOrigin(token); return(result); }
private async Task <GitCommandResponse> PerformPushForce(CancellationToken token) { if (token.IsCancellationRequested) { return(null); } GitCommandResponse forcePushOutput = await this.SquashWrapper.PushForce(token); return(forcePushOutput); }
/// <inheritdoc /> public async Task <GitCommandResponse> Rebase(CancellationToken token, GitBranch parentBranch) { if (await this.branchManager.IsWorkingDirectoryDirty(token)) { return(new GitCommandResponse(false, "Cannot rebase: You have unstaged changes.", null, 0)); } GitCommandResponse response = await this.FetchOrigin(token); if (response.Success == false) { return(response); } return(await this.gitProcess.RunGit($"rebase {parentBranch.FriendlyName}", token)); }