Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Stack/Commands/Branch/AddBranchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override async Task Handle(AddBranchCommandInputs inputs, CancellationTok
}
}

logger.AddingBranchToStack(branchName.Branch(), stack.Name.Stack());
logger.AddingBranchToStack(branchName, stack.Name);

if (sourceBranch is not null)
{
Expand All @@ -113,7 +113,7 @@ public override async Task Handle(AddBranchCommandInputs inputs, CancellationTok

stackConfig.Save(stackData);

logger.BranchAdded(branchName.Branch(), stack.Name.Stack());
logger.BranchAdded(branchName, stack.Name);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Stack/Commands/Branch/NewBranchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override async Task Handle(NewBranchCommandInputs inputs, CancellationTok

var sourceBranchName = sourceBranch?.Name ?? stack.SourceBranch;

logger.CreatingBranch(branchName.Branch(), sourceBranchName.Branch(), stack.Name.Stack());
logger.CreatingBranch(branchName, sourceBranchName, stack.Name);

gitClient.CreateNewBranch(branchName, sourceBranchName);

Expand All @@ -119,16 +119,16 @@ public override async Task Handle(NewBranchCommandInputs inputs, CancellationTok

stackConfig.Save(stackData);

logger.BranchCreated(branchName.Branch());
logger.BranchCreated(branchName);

try
{
logger.PushingBranchToRemote(branchName.Branch());
logger.PushingBranchToRemote(branchName);
gitClient.PushNewBranch(branchName);
}
catch (Exception)
{
logger.NewBranchPushWarning(branchName.Branch(), stack.Name);
logger.NewBranchPushWarning(branchName, stack.Name);
}

gitClient.ChangeBranch(branchName);
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Commands/Branch/RemoveBranchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ await inputProvider.Select(
stack.RemoveBranch(branchName, action);
stackConfig.Save(stackData);

logger.BranchRemovedFromStack(branchName.Branch(), stack.Name.Stack());
logger.BranchRemovedFromStack(branchName, stack.Name);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Stack/Commands/Helpers/StackActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public void PullChanges(Config.Stack stack)

if (shouldPullCurrent)
{
logger.PullingCurrentBranch(currentBranch.Branch());
logger.PullingCurrentBranch(currentBranch);
gitClient.PullBranch(currentBranch);
}

// Pull branches that are in other worktrees directly
foreach (var branch in branchesInOtherWorktrees)
{
var worktreePath = branchStatus[branch].WorktreePath!; // not null due to filter
logger.PullingWorktreeBranch(branch.Branch(), worktreePath);
logger.PullingWorktreeBranch(branch, worktreePath);
gitClient.PullBranchForWorktree(branch, worktreePath);
}

if (nonCurrentBranches.Length > 0)
{
logger.FetchingNonCurrentBranches(string.Join(", ", nonCurrentBranches.Select(b => b.Branch())));
logger.FetchingNonCurrentBranches(string.Join(", ", nonCurrentBranches));
gitClient.FetchBranchRefSpecs(nonCurrentBranches);
}
}
Expand All @@ -86,7 +86,7 @@ public void PushChanges(

foreach (var branch in branchesThatHaveNotBeenPushedToRemote)
{
logger.PushingNewBranch(branch.Branch());
logger.PushingNewBranch(branch);
gitClient.PushNewBranch(branch);
}

Expand All @@ -103,7 +103,7 @@ public void PushChanges(

foreach (var branches in branchGroupsToPush)
{
logger.PushingBranches(string.Join(", ", branches.Select(b => b.Branch())));
logger.PushingBranches(string.Join(", ", branches));
gitClient.PushBranches([.. branches], forceWithLease);
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ private async Task UpdateStackUsingMerge(
StackStatus status,
CancellationToken cancellationToken)
{
logger.UpdatingStackUsingMerge(status.Name.Stack());
logger.UpdatingStackUsingMerge(status.Name);

var allBranchLines = status.GetAllBranchLines();

Expand Down Expand Up @@ -168,7 +168,7 @@ private async Task UpdateBranchLineUsingMerge(

private async Task MergeFromSourceBranch(string branch, string sourceBranchName, CancellationToken cancellationToken)
{
logger.MergingBranch(sourceBranchName.Branch(), branch.Branch());
logger.MergingBranch(sourceBranchName, branch);
gitClient.ChangeBranch(branch);

try
Expand Down Expand Up @@ -201,7 +201,7 @@ private async Task UpdateStackUsingRebase(
StackStatus status,
CancellationToken cancellationToken)
{
logger.UpdatingStackUsingRebase(status.Name.Stack());
logger.UpdatingStackUsingRebase(status.Name);

var allBranchLines = status.GetAllBranchLines();

Expand Down Expand Up @@ -241,7 +241,7 @@ private async Task UpdateBranchLineUsingRebase(StackStatus status, List<BranchDe
// all commits from feature3 (and therefore from feature2) on top of the latest commits of main
// which will include the squashed commit.
//
logger.RebasingStackForBranchLine(status.Name.Stack(), status.SourceBranch.Name.Branch(), string.Join(" -> ", branchLine.Select(b => b.Name.Branch())));
logger.RebasingStackForBranchLine(status.Name, status.SourceBranch.Name, string.Join(" -> ", branchLine.Select(b => b.Name)));

BranchDetail? lowestActionBranch = null;
foreach (var branch in branchLine)
Expand Down Expand Up @@ -298,7 +298,7 @@ private async Task UpdateBranchLineUsingRebase(StackStatus status, List<BranchDe

private async Task RebaseFromSourceBranch(string branch, string sourceBranchName, CancellationToken cancellationToken)
{
logger.RebasingBranchOnto(branch.Branch(), sourceBranchName.Branch());
logger.RebasingBranchOnto(branch, sourceBranchName);
gitClient.ChangeBranch(branch);

try
Expand All @@ -317,7 +317,7 @@ private async Task RebaseOntoNewParent(
string oldParentBranchName,
CancellationToken cancellationToken)
{
logger.RebasingBranchOntoNewParent(branch.Branch(), newParentBranchName.Branch());
logger.RebasingBranchOntoNewParent(branch, newParentBranchName);
gitClient.ChangeBranch(branch);

try
Expand Down
102 changes: 38 additions & 64 deletions src/Stack/Commands/Helpers/StackHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using MoreLinq;
using Spectre.Console;
Expand Down Expand Up @@ -142,7 +143,7 @@ static void EvaluateBranchStatusDetails(ILogger logger, IGitClient gitClient, IG
{
if (!branchStatuses.TryGetValue(stack.SourceBranch, out var sourceBranchStatus))
{
logger.SourceBranchDoesNotExist(stack.SourceBranch.Branch());
logger.SourceBranchDoesNotExist(stack.SourceBranch);
continue;
}

Expand Down Expand Up @@ -246,20 +247,22 @@ public static StackStatus GetStackStatus(
return statuses.First();
}

public static void OutputStackStatus(
public static async Task OutputStackStatus(
List<StackStatus> statuses,
IDisplayProvider displayProvider)
IDisplayProvider displayProvider,
CancellationToken cancellationToken)
{
foreach (var status in statuses)
{
OutputStackStatus(status, displayProvider);
displayProvider.DisplayNewLine();
await OutputStackStatus(status, displayProvider, cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}
}

public static void OutputStackStatus(
public static async Task OutputStackStatus(
StackStatus status,
IDisplayProvider displayProvider,
CancellationToken cancellationToken,
Func<BranchDetail, string?>? getBranchPullRequestDisplay = null)
{
var header = GetBranchStatusOutput(status.SourceBranch);
Expand All @@ -270,8 +273,8 @@ public static void OutputStackStatus(
items.Add(GetBranchAndPullRequestStatusOutput(branch, getBranchPullRequestDisplay));
}

displayProvider.DisplayMessage(status.Name.Stack());
displayProvider.DisplayTree(header, [.. items]);
await displayProvider.DisplayMessage(status.Name.Stack(), cancellationToken);
await displayProvider.DisplayTree(header, [.. items], cancellationToken: cancellationToken);
}

public static TreeItem<string> GetBranchAndPullRequestStatusOutput(
Expand Down Expand Up @@ -434,49 +437,50 @@ public static string GetBranchStatusOutput(BranchDetail branch)
return branchNameBuilder.ToString();
}

public static void OutputBranchAndStackActions(
public static async Task OutputBranchAndStackActions(
StackStatus status,
ILogger logger)
IDisplayProvider displayProvider,
CancellationToken cancellationToken)
{
var allBranches = status.GetAllBranches();
if (allBranches.All(branch => branch.CouldBeCleanedUp))
{
logger.AllBranchesMightBeDeleted();
logger.NewLine();
logger.RunDeleteStackCommand(status.Name);
logger.NewLine();
await displayProvider.DisplayMessage("All branches exist locally but are either not in the remote repository or the pull request associated with the branch is no longer open. This stack might be able to be deleted.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack delete --stack \"{status.Name}\"".Example()} to delete the stack if it's no longer needed.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}
else if (allBranches.Any(branch => branch.CouldBeCleanedUp))
{
logger.SomeBranchesCouldBeCleanedUp();
logger.NewLine();
logger.RunCleanupStackCommand(status.Name);
logger.NewLine();
await displayProvider.DisplayMessage("Some branches exist locally but are either not in the remote repository or the pull request associated with the branch is no longer open.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack cleanup --stack \"{status.Name}\"".Example()} to clean up the stack if it's no longer needed.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}
else if (allBranches.All(branch => !branch.Exists))
{
logger.NoLocalBranchesStackMightBeDeleted();
logger.NewLine();
logger.RunDeleteStackCommand(status.Name);
logger.NewLine();
await displayProvider.DisplayMessage("No branches exist locally. This stack might be able to be deleted.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack delete --stack \"{status.Name}\"".Example()} to delete the stack if it's no longer needed.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}

if (allBranches.Any(branch => branch.Exists && (branch.RemoteTrackingBranch is null || branch.RemoteTrackingBranch.Ahead > 0)))
{
logger.ChangesNotPushedToRemote();
logger.NewLine();
logger.RunPushStackCommand(status.Name);
logger.NewLine();
await displayProvider.DisplayMessage("There are changes in local branches that have not been pushed to the remote repository.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack push --stack \"{status.Name}\"".Example()} to push the changes to the remote repository.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}

if (allBranches.Any(branch => branch.Exists && branch.RemoteTrackingBranch is not null && branch.RemoteTrackingBranch.Behind > 0))
{
logger.SourceChangesNotApplied();
logger.NewLine();
logger.RunUpdateStackCommand(status.Name);
logger.NewLine();
logger.RunSyncStackCommand(status.Name);
logger.NewLine();
await displayProvider.DisplayMessage("There are changes in source branches that have not been applied to the stack.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack update --stack \"{status.Name}\"".Example()} to update the stack locally.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
await displayProvider.DisplayMessage($"Run {$"stack sync --stack \"{status.Name}\"".Example()} to sync the stack with the remote repository.", cancellationToken);
await displayProvider.DisplayNewLine(cancellationToken);
}
}

Expand Down Expand Up @@ -542,15 +546,15 @@ public static void OutputBranchesNeedingCleanup(ILogger logger, string[] branche

foreach (var branch in branches)
{
logger.BranchToCleanup(branch.Branch());
logger.BranchToCleanup(branch);
}
}

public static void CleanupBranches(IGitClient gitClient, ILogger logger, string[] branches)
{
foreach (var branch in branches)
{
logger.DeletingLocalBranch(branch.Branch());
logger.DeletingLocalBranch(branch);
gitClient.DeleteLocalBranch(branch);
}
}
Expand Down Expand Up @@ -630,36 +634,6 @@ internal static partial class LoggerExtensionMethods
[LoggerMessage(Level = LogLevel.Warning, Message = "Source branch {SourceBranch} does not exist locally or in the remote repository.")]
public static partial void SourceBranchDoesNotExist(this ILogger logger, string sourceBranch);

[LoggerMessage(Level = LogLevel.Information, Message = "All branches exist locally but are either not in the remote repository or the pull request associated with the branch is no longer open. This stack might be able to be deleted.")]
public static partial void AllBranchesMightBeDeleted(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "Run 'stack delete --stack \"{Stack}\"' to delete the stack if it's no longer needed.")]
public static partial void RunDeleteStackCommand(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "Some branches exist locally but are either not in the remote repository or the pull request associated with the branch is no longer open.")]
public static partial void SomeBranchesCouldBeCleanedUp(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "Run 'stack cleanup --stack \"{Stack}\"' to clean up local branches.")]
public static partial void RunCleanupStackCommand(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "No branches exist locally. This stack might be able to be deleted.")]
public static partial void NoLocalBranchesStackMightBeDeleted(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "There are changes in local branches that have not been pushed to the remote repository.")]
public static partial void ChangesNotPushedToRemote(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "Run 'stack push --stack \"{Stack}\"' to push the changes to the remote repository.")]
public static partial void RunPushStackCommand(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "There are changes in source branches that have not been applied to the stack.")]
public static partial void SourceChangesNotApplied(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "Run 'stack update --stack \"{Stack}\"' to update the stack locally.")]
public static partial void RunUpdateStackCommand(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "Run 'stack sync --stack \"{Stack}\"' to sync the stack with the remote repository.")]
public static partial void RunSyncStackCommand(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "The following branches exist locally but are either not in the remote repository or the pull request associated with the branch is no longer open:")]
public static partial void BranchesToCleanupHeader(this ILogger logger);

Expand Down
Loading
Loading