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
15 changes: 12 additions & 3 deletions src/Stack/Commands/Branch/AddBranchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override async Task Handle(AddBranchCommandInputs inputs, CancellationTok

if (stacksForRemote.Count == 0)
{
logger.LogInformation("No stacks found for current repository.");
logger.NoStacksForRepository();
return;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public override async Task Handle(AddBranchCommandInputs inputs, CancellationTok
}
}

logger.LogInformation($"Adding branch {branchName.Branch()} to stack {stack.Name.Stack()}");
logger.AddingBranchToStack(branchName.Branch(), stack.Name.Stack());

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

stackConfig.Save(stackData);

logger.LogInformation($"Branch added");
logger.BranchAdded(branchName.Branch(), stack.Name.Stack());
}
}

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Trace, Message = "Adding branch {Branch} to stack \"{Stack}\".")]
public static partial void AddingBranchToStack(this ILogger logger, string branch, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "Branch {Branch} added to stack \"{Stack}\".")]
public static partial void BranchAdded(this ILogger logger, string branch, string stack);
}
22 changes: 17 additions & 5 deletions src/Stack/Commands/Branch/NewBranchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override async Task Handle(NewBranchCommandInputs inputs, CancellationTok

if (stacksForRemote.Count == 0)
{
logger.LogInformation("No stacks found for current repository.");
logger.NoStacksForRepository();
return;
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public override async Task Handle(NewBranchCommandInputs inputs, CancellationTok

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

logger.LogInformation($"Creating branch {branchName.Branch()} from {sourceBranchName.Branch()} in stack {stack.Name.Stack()}");
logger.CreatingBranch(branchName.Branch(), sourceBranchName.Branch(), stack.Name.Stack());

gitClient.CreateNewBranch(branchName, sourceBranchName);

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

stackConfig.Save(stackData);

logger.LogInformation($"Branch {branchName.Branch()} created.");
logger.BranchCreated(branchName.Branch());

try
{
logger.LogInformation($"Pushing branch {branchName.Branch()} to remote repository");
logger.PushingBranchToRemote(branchName.Branch());
gitClient.PushNewBranch(branchName);
}
catch (Exception)
{
logger.LogWarning($"An error has occurred pushing branch {branchName.Branch()} to remote repository. Use {$"stack push --name \"{stack.Name}\"".Example()} to push the branch to the remote repository.");
logger.NewBranchPushWarning(branchName.Branch(), stack.Name);
}

gitClient.ChangeBranch(branchName);
}
}

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Information, Message = "Creating branch {Branch} from {SourceBranch} in stack \"{Stack}\"")]
public static partial void CreatingBranch(this ILogger logger, string branch, string sourceBranch, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "Branch {Branch} created.")]
public static partial void BranchCreated(this ILogger logger, string branch);

[LoggerMessage(Level = LogLevel.Information, Message = "Pushing branch {Branch} to remote repository")]
public static partial void PushingBranchToRemote(this ILogger logger, string branch);
}
8 changes: 7 additions & 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.LogInformation($"Branch {branchName.Branch()} removed from stack {stack.Name.Stack()}");
logger.BranchRemovedFromStack(branchName.Branch(), stack.Name.Stack());
}
}
}
Expand All @@ -122,3 +122,9 @@ public enum RemoveBranchChildAction
RemoveChildren
}

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Information, Message = "Branch {Branch} removed from stack \"{Stack}\"")]
public static partial void BranchRemovedFromStack(this ILogger logger, string branch, string stack);
}

8 changes: 7 additions & 1 deletion src/Stack/Commands/Config/OpenConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override async Task Execute(ParseResult parseResult, CancellationToken

if (!File.Exists(configPath))
{
Logger.LogInformation("No config file found.");
Logger.NoConfigFileFound();
return;
}

Expand All @@ -43,3 +43,9 @@ protected override async Task Execute(ParseResult parseResult, CancellationToken
return;
}
}

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Information, Message = "No config file found.")]
public static partial void NoConfigFileFound(this ILogger logger);
}
10 changes: 5 additions & 5 deletions src/Stack/Commands/Helpers/InputProviderExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task<string> Text(
{
if (presetValue is not null)
{
logger.LogInformation($"{prompt} {presetValue}");
logger.Answer(prompt, presetValue);

return presetValue;
}
Expand All @@ -35,7 +35,7 @@ public static async Task<string> Select(
{
var selection = presetValue ?? await inputProvider.Select(prompt, choices, cancellationToken);

logger.LogInformation($"{prompt} {selection}");
logger.Answer(prompt, selection);

return selection;
}
Expand All @@ -51,7 +51,7 @@ public static async Task<string[]> MultiSelect(
{
var selection = presetValues ?? (await inputProvider.MultiSelect(prompt, choices, required, cancellationToken)).ToArray();

logger.LogInformation($"{prompt} {string.Join(", ", selection)}");
logger.Answer(prompt, string.Join(", ", selection));

return [.. selection];
}
Expand All @@ -73,7 +73,7 @@ public static async Task<string[]> MultiSelect(

if (stack is not null)
{
logger.LogInformation($"{Questions.SelectStack} {stack.Name}");
logger.Answer(Questions.SelectStack, stack.Name);
}

return stack;
Expand Down Expand Up @@ -113,7 +113,7 @@ void GetBranchNamesWithIndentation(Branch branch, List<string> names, int level

var branchSelection = (name ?? await inputProvider.Select(Questions.SelectParentBranch, [stack.SourceBranch, .. allBranchNamesWithLevel], cancellationToken)).Trim();

logger.LogInformation($"{Questions.SelectParentBranch} {branchSelection}");
logger.Answer(Questions.SelectParentBranch, branchSelection);

return branchSelection;
}
Expand Down
69 changes: 55 additions & 14 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.LogInformation($"Pulling changes for {currentBranch.Branch()} from remote");
logger.PullingCurrentBranch(currentBranch.Branch());
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.LogInformation($"Pulling changes for {branch.Branch()} (worktree: {worktreePath}) from remote");
logger.PullingWorktreeBranch(branch.Branch(), worktreePath);
gitClient.PullBranchForWorktree(branch, worktreePath);
}

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

foreach (var branch in branchesThatHaveNotBeenPushedToRemote)
{
logger.LogInformation($"Pushing new branch {branch.Branch()} to remote");
logger.PushingNewBranch(branch.Branch());
gitClient.PushNewBranch(branch);
}

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

foreach (var branches in branchGroupsToPush)
{
logger.LogInformation($"Pushing changes for {string.Join(", ", branches.Select(b => b.Branch()))} to remote");

logger.PushingBranches(string.Join(", ", branches.Select(b => b.Branch())));
gitClient.PushBranches([.. branches], forceWithLease);
}
}
Expand Down Expand Up @@ -137,7 +136,7 @@ private async Task UpdateStackUsingMerge(
StackStatus status,
CancellationToken cancellationToken)
{
logger.LogInformation($"Updating stack {status.Name.Stack()} using merge...");
logger.UpdatingStackUsingMerge(status.Name.Stack());

var allBranchLines = status.GetAllBranchLines();

Expand All @@ -162,14 +161,14 @@ private async Task UpdateBranchLineUsingMerge(
}
else
{
logger.LogTrace($"Branch '{branch}' no longer exists on the remote repository or the associated pull request is no longer open. Skipping...");
logger.TraceSkippingInactiveBranch(branch.Name);
}
}
}

private async Task MergeFromSourceBranch(string branch, string sourceBranchName, CancellationToken cancellationToken)
{
logger.LogInformation($"Merging {sourceBranchName.Branch()} into {branch.Branch()}");
logger.MergingBranch(sourceBranchName.Branch(), branch.Branch());
gitClient.ChangeBranch(branch);

try
Expand Down Expand Up @@ -202,7 +201,7 @@ private async Task UpdateStackUsingRebase(
StackStatus status,
CancellationToken cancellationToken)
{
logger.LogInformation($"Updating stack {status.Name.Stack()} using rebase...");
logger.UpdatingStackUsingRebase(status.Name.Stack());

var allBranchLines = status.GetAllBranchLines();

Expand Down Expand Up @@ -242,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.LogInformation($"Rebasing stack {status.Name.Stack()} for branch line: {status.SourceBranch.Name.Branch()} --> {string.Join(" -> ", branchLine.Select(b => b.Name.Branch()))}");
logger.RebasingStackForBranchLine(status.Name.Stack(), status.SourceBranch.Name.Branch(), string.Join(" -> ", branchLine.Select(b => b.Name.Branch())));

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

if (lowestActionBranch is null)
{
logger.LogWarning("No active branches found in the stack.");
logger.NoActiveBranchesFound();
return;
}

Expand Down Expand Up @@ -299,7 +298,7 @@ private async Task UpdateBranchLineUsingRebase(StackStatus status, List<BranchDe

private async Task RebaseFromSourceBranch(string branch, string sourceBranchName, CancellationToken cancellationToken)
{
logger.LogInformation($"Rebasing {branch.Branch()} onto {sourceBranchName.Branch()}");
logger.RebasingBranchOnto(branch.Branch(), sourceBranchName.Branch());
gitClient.ChangeBranch(branch);

try
Expand All @@ -318,7 +317,7 @@ private async Task RebaseOntoNewParent(
string oldParentBranchName,
CancellationToken cancellationToken)
{
logger.LogInformation($"Rebasing {branch.Branch()} onto new parent {newParentBranchName.Branch()}");
logger.RebasingBranchOntoNewParent(branch.Branch(), newParentBranchName.Branch());
gitClient.ChangeBranch(branch);

try
Expand Down Expand Up @@ -363,3 +362,45 @@ private async Task HandleConflictsDuringRebase(CancellationToken cancellationTok
}
}
}

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Information, Message = "Pulling changes for {Branch} from remote")]
public static partial void PullingCurrentBranch(this ILogger logger, string branch);

[LoggerMessage(Level = LogLevel.Information, Message = "Pulling changes for {Branch} (worktree: \"{WorktreePath}\") from remote")]
public static partial void PullingWorktreeBranch(this ILogger logger, string branch, string worktreePath);

[LoggerMessage(Level = LogLevel.Information, Message = "Fetching changes for {Branches} from remote")]
public static partial void FetchingNonCurrentBranches(this ILogger logger, string branches);

[LoggerMessage(Level = LogLevel.Information, Message = "Pushing new branch {Branch} to remote")]
public static partial void PushingNewBranch(this ILogger logger, string branch);

[LoggerMessage(Level = LogLevel.Information, Message = "Pushing changes for {Branches} to remote")]
public static partial void PushingBranches(this ILogger logger, string branches);

[LoggerMessage(Level = LogLevel.Information, Message = "Updating stack \"{Stack}\" using merge...")]
public static partial void UpdatingStackUsingMerge(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Trace, Message = "Branch {Branch} no longer exists on the remote repository or the associated pull request is no longer open. Skipping...")]
public static partial void TraceSkippingInactiveBranch(this ILogger logger, string branch);

[LoggerMessage(Level = LogLevel.Information, Message = "Merging {SourceBranch} into {Branch}")]
public static partial void MergingBranch(this ILogger logger, string sourceBranch, string branch);

[LoggerMessage(Level = LogLevel.Information, Message = "Updating stack \"{Stack}\" using rebase...")]
public static partial void UpdatingStackUsingRebase(this ILogger logger, string stack);

[LoggerMessage(Level = LogLevel.Information, Message = "Rebasing stack \"{Stack}\" for branch line: {SourceBranch} --> {BranchLine}")]
public static partial void RebasingStackForBranchLine(this ILogger logger, string stack, string sourceBranch, string branchLine);

[LoggerMessage(Level = LogLevel.Debug, Message = "No active branches found for branch line.")]
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log level should be LogLevel.Warning to match the original code at line 257 which used logger.LogWarning.

Suggested change
[LoggerMessage(Level = LogLevel.Debug, Message = "No active branches found for branch line.")]
[LoggerMessage(Level = LogLevel.Warning, Message = "No active branches found for branch line.")]

Copilot uses AI. Check for mistakes.
public static partial void NoActiveBranchesFound(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "Rebasing {Branch} onto {SourceBranch}")]
public static partial void RebasingBranchOnto(this ILogger logger, string branch, string sourceBranch);

[LoggerMessage(Level = LogLevel.Information, Message = "Rebasing {Branch} onto new parent {NewParentBranch}")]
public static partial void RebasingBranchOntoNewParent(this ILogger logger, string branch, string newParentBranch);
}
Loading
Loading