From 6064b2aa5aff68ec8b0b06e6f7e8e8fa528e61f6 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:22:16 +0100 Subject: [PATCH 1/7] Refactor CLI commands: standardize `_gitRepository` usage, replace `ISysConsole` with `IAnsiConsole`, and introduce extension methods for markup rendering. --- .../BranchGroup/Info/InfoBranchesCommand.cs | 12 ++- .../BranchGroup/List/ListBranchesCommand.cs | 6 +- .../BranchGroup/Pull/PullBranchCommand.cs | 4 +- .../BranchGroup/Push/PushBranchCommand.cs | 4 +- .../Update/UpdateBranchesCommand.cs | 16 +-- .../Finish/FeatureFinishFailedException.cs | 9 +- .../Finish/FinishFeatureCommand.cs | 16 +-- .../FeatureGroup/Finish/FinishFeatureData.cs | 31 +++--- .../FeatureGroup/Finish/FinishFeatureSteps.cs | 100 ++++++++++-------- .../Shared/AnsiConsoleExtensions.cs | 20 ++++ .../Shared/StringExtensions.cs | 19 ++++ 11 files changed, 147 insertions(+), 90 deletions(-) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs index ba7adec..4d36a3f 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs @@ -14,6 +14,8 @@ public class InfoBranchesCommand(IAnsiConsole ansiConsole, IGitRepository gitRep { private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + public Task ExecuteAsync(InfoBranchesOptions options) { _ansiConsole.WriteLine("Branch info"); @@ -24,12 +26,12 @@ public Task ExecuteAsync(InfoBranchesOptions options) .HideHeaders() .AddColumn("Name") .AddColumn("Value") - .AddRow("Current branch:", gitRepository.Head.Name.Canonical) - .AddRow("Last Commit:", gitRepository.Head.Tip?.Sha ?? string.Empty); + .AddRow("Current branch:", _gitRepository.Head.Name.Canonical) + .AddRow("Last Commit:", _gitRepository.Head.Tip?.Sha ?? string.Empty); - if (gitRepository.Head.TrackedBranch != null) + if (_gitRepository.Head.TrackedBranch != null) { - table.AddRow("Last tracked commit:", gitRepository.Head.TrackedBranch?.Tip?.Sha ?? string.Empty); + table.AddRow("Last tracked commit:", _gitRepository.Head.TrackedBranch?.Tip?.Sha ?? string.Empty); } _ansiConsole.Write(table); @@ -37,7 +39,7 @@ public Task ExecuteAsync(InfoBranchesOptions options) _ansiConsole.WriteLine(); _ansiConsole.WriteLine("Last commits"); - var commits = gitRepository.Head.Commits?.Take(options.CommitLogCount); + var commits = _gitRepository.Head.Commits?.Take(options.CommitLogCount); if (commits != null) { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs index 79b513d..793baef 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs @@ -15,9 +15,11 @@ public class ListBranchesCommand(ISysConsole sysConsole, IGitRepository gitRepos { private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + private void PrintBranch(IGitBranch branch, int column0Width, int column1Width) { - var isHead = branch.Equals(gitRepository.Head); + var isHead = branch.Equals(_gitRepository.Head); _sysConsole.Write(isHead ? " * " : " "); @@ -43,7 +45,7 @@ public Task ExecuteAsync(ListBranchesOptions options) .WriteLine("List all branches:") .WriteLine(); - var branches = gitRepository + var branches = _gitRepository .Branches .Where(x => options.Location == BranchLocation.All diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs index 69a1791..bed391e 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs @@ -13,8 +13,10 @@ public class PullBranchCommand(IGitToolPullCommand pullCommand, IGitRepository g { private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + public async Task ExecuteAsync(PullBranchOptions options) { - return await _pullCommand.ExecuteAsync(gitRepository, options.Verbose).ConfigureAwait(false); + return await _pullCommand.ExecuteAsync(_gitRepository, options.Verbose).ConfigureAwait(false); } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs index e36cc65..23e5675 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs @@ -13,10 +13,12 @@ public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository g { private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + public async Task ExecuteAsync(PushBranchOptions options) { return await _pushCommand - .ExecuteAsync(gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) + .ExecuteAsync(_gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) .ConfigureAwait(false); } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs index 254e371..6aa8181 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs @@ -30,6 +30,8 @@ public class UpdateBranchesCommand( private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + public async Task ExecuteAsync(UpdateBranchesOptions options) { Ensure.NotNull(options); @@ -39,14 +41,14 @@ public async Task ExecuteAsync(UpdateBranchesOptions options) .WriteMarkupLine(_cml.Caption("Update permanent local branches")) .EmptyLine(); - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + var configuration = _repositoryConfigurations.GetConfiguration(_gitRepository); - var currentBranch = gitRepository.Head; + var currentBranch = _gitRepository.Head; var updateBranchNames = new List { "production", - GitBranchNames.Local.GetFriendlyName(gitRepository.Info.MainBranch) + GitBranchNames.Local.GetFriendlyName(_gitRepository.Info.MainBranch) }; if (configuration.HasDevelopBranch) @@ -58,17 +60,17 @@ public async Task ExecuteAsync(UpdateBranchesOptions options) { _ansiConsole.WriteLine("Fetch prune to remove remote branch refs if already deleted"); - gitRepository.FetchPruneFromOrigin(); + _gitRepository.FetchPruneFromOrigin(); } - await UpdateBranchesAsync(gitRepository, updateBranchNames).ConfigureAwait(false); + await UpdateBranchesAsync(_gitRepository, updateBranchNames).ConfigureAwait(false); - if (!gitRepository.Head.Equals(currentBranch)) + if (!_gitRepository.Head.Equals(currentBranch)) { _ansiConsole.WriteMarkupLine( $"Switch back to working branch {_cml.HighLight($"'{currentBranch.Name.Friendly}'")}"); - gitRepository.Branches.CheckOut(currentBranch.Name.Friendly); + _gitRepository.Branches.CheckOut(currentBranch.Name.Friendly); } _ansiConsole.EmptyLine(); diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs index e99744b..c4b8e67 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs @@ -2,10 +2,5 @@ namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; -public class FeatureFinishFailedException : CliExitException -{ - public FeatureFinishFailedException(string message, int exitCode, Exception? exception = null) : base(message, - exitCode, exception) - { - } -} +public class FeatureFinishFailedException(string message, int exitCode, Exception? exception = null) + : CliExitException(message, exitCode, exception); diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs index 50148a6..878dc95 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs @@ -20,12 +20,16 @@ public class FinishFeatureCommand( private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + private FinishFeatureData CreateData(FinishFeatureOptions options) { - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + var configuration = _repositoryConfigurations.GetConfiguration(_gitRepository); - return new FinishFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), - configuration.GetDefaultBranchName(gitRepository.Info.MainBranch), configuration.GitServiceProviderName, + return new FinishFeatureData(_gitRepository, configuration.GetFeatureBranchName(options.FeatureName), + configuration.GetDefaultBranchName(_gitRepository.Info.MainBranch), configuration.GitServiceProviderName, options.PullRequestTitle); } @@ -47,14 +51,14 @@ public async Task ExecuteAsync(FinishFeatureOptions options) } catch (FeatureFinishFailedException e) { - ansiConsole.MarkupLine($"[red]{e.Message}[/]"); + _ansiConsole.MarkupLine($"[red]{e.Message}[/]"); return e.ExitCode; } - gitRepository.Branches.CheckOut(data.DefaultBranch); + _gitRepository.Branches.CheckOut(data.DefaultBranch); - gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); + _gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); return CommandResult.Success; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs index b29afd9..f65c122 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs @@ -1,26 +1,23 @@ -using CreativeCoders.Git.Abstractions; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; -public class FinishFeatureData +public class FinishFeatureData( + IGitRepository repository, + string featureBranch, + string defaultBranch, + string repositoryGitServiceProviderName, + string? pullRequestTitle) { - public FinishFeatureData(IGitRepository repository, string featureBranch, string defaultBranch, - string repositoryGitServiceProviderName, string? pullRequestTitle) - { - Repository = repository; - FeatureBranch = featureBranch; - DefaultBranch = defaultBranch; - RepositoryGitServiceProviderName = repositoryGitServiceProviderName; - PullRequestTitle = pullRequestTitle; - } + public string FeatureBranch { get; } = Ensure.IsNotNullOrWhitespace(featureBranch); - public string FeatureBranch { get; } + public string DefaultBranch { get; } = Ensure.IsNotNullOrWhitespace(defaultBranch); - public string DefaultBranch { get; } + public string RepositoryGitServiceProviderName { get; } = + Ensure.IsNotNullOrWhitespace(repositoryGitServiceProviderName); - public string RepositoryGitServiceProviderName { get; } + public string? PullRequestTitle { get; } = pullRequestTitle; - public string? PullRequestTitle { get; } - - public IGitRepository Repository { get; } + public IGitRepository Repository { get; } = Ensure.NotNull(repository); } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs index ee7de64..dfbea7c 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs @@ -3,104 +3,113 @@ using CreativeCoders.Git.Abstractions.Commits; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Exceptions; -using CreativeCoders.SysConsole.Core.Abstractions; +using CreativeCoders.GitTool.Cli.Commands.Shared; +using Spectre.Console; using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public class FinishFeatureSteps( - ISysConsole sysConsole, + IAnsiConsole ansiConsole, IGitServiceProviders gitServiceProviders, IGitToolPushCommand pushCommand) : IFinishFeatureSteps { private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); public void UpdateFeatureBranch(FinishFeatureData data) { - _sysConsole.WriteLine($"Checkout feature branch '{data.FeatureBranch}'"); + _ansiConsole.WriteLine($"Checkout feature branch '{data.FeatureBranch}'"); data.Repository.Branches.CheckOut(data.FeatureBranch); if (data.Repository.HasUncommittedChanges(true)) { - _sysConsole - .WriteLineError("Feature branch has uncommitted changes. Please commit or revert and try again") - .WriteLine(); + _ansiConsole.MarkupLines([ + "Feature branch has uncommitted changes. Please commit or revert and try again".ToErrorMarkup(), + string.Empty + ]); throw new FeatureFinishFailedException("Feature branch has uncommitted changes", ReturnCodes.BranchHasUncommittedChanges); } - _sysConsole - .WriteLine("Feature branch checked out") - .WriteLine(); + _ansiConsole.WriteLines([ + "Feature branch checked out", + string.Empty + ]); if (data.Repository.Branches[data.FeatureBranch]?.TrackedBranch == null) { return; } - _sysConsole + _ansiConsole .WriteLine("Pull feature branch updates from remote"); var mergeResult = data.Repository.Pull(); - _sysConsole.WriteLine($"Pull merge result {mergeResult.MergeStatus}"); + _ansiConsole.WriteLine($"Pull merge result {mergeResult.MergeStatus}"); if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _sysConsole - .WriteLineError("Pull feature branch updates from remote caused merge conflicts") - .WriteLineError("Resolve conflicts and try again"); + _ansiConsole.MarkupLines([ + "Pull feature branch updates from remote caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup() + ]); throw new FeatureFinishFailedException("Merge feature branch from remote into local caused merge conflicts", ReturnCodes.MergeConflicts); } - _sysConsole - .WriteLine("Feature branch updates pulled from remote") - .WriteLine(); + _ansiConsole.WriteLines([ + "Feature branch updates pulled from remote", + string.Empty + ]); } public void MergeDefaultBranch(FinishFeatureData data) { - _sysConsole.WriteLine("Checkout Default branch"); + _ansiConsole.WriteLine("Checkout Default branch"); data.Repository.Branches.CheckOut(data.DefaultBranch); - _sysConsole - .WriteLine("Default branch checked out") - .WriteLine() - .WriteLine("Pull default branch updates from remote"); + _ansiConsole.WriteLines([ + "Default branch checked out", + string.Empty, + "Pull default branch updates from remote" + ]); var mergeResult = data.Repository.Pull(); if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _sysConsole - .WriteLineError("Pull default branch updates from remote caused merge conflicts") - .WriteLineError("Resolve conflicts and try again"); + _ansiConsole.MarkupLines([ + "Pull default branch updates from remote caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup() + ]); throw new FeatureFinishFailedException("Merge default branch from remote into local caused merge conflicts", ReturnCodes.MergeConflicts); } - _sysConsole - .WriteLine("Default branch updates pulled from remote") - .WriteLine(); + _ansiConsole.WriteLines([ + "Default branch updates pulled from remote", + string.Empty + ]); mergeResult = data.Repository.Merge(data.DefaultBranch, data.FeatureBranch, new GitMergeOptions()); if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _sysConsole - .WriteLineError("Merge default branch to feature branch caused merge conflicts") - .WriteLineError("Resolve conflicts and try again"); + _ansiConsole.MarkupLines([ + "Merge default branch to feature branch caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup() + ]); throw new FeatureFinishFailedException("Merge default branch to feature branch caused merge conflicts", ReturnCodes.MergeConflicts); @@ -111,7 +120,7 @@ public void MergeDefaultBranch(FinishFeatureData data) public async Task PushFeatureBranch(FinishFeatureData data) { - _sysConsole + _ansiConsole .WriteLine("Push feature branch to remote"); if (!data.Repository.Head.BranchIsPushedToRemote()) @@ -119,9 +128,10 @@ public async Task PushFeatureBranch(FinishFeatureData data) await _pushCommand.ExecuteAsync(data.Repository, true, false).ConfigureAwait(false); } - _sysConsole - .WriteLine("Feature branch pushed to remote") - .WriteLine(); + _ansiConsole.WriteLines([ + "Feature branch pushed to remote", + string.Empty + ]); } public async Task CreatePullRequest(FinishFeatureData data) @@ -132,7 +142,7 @@ public async Task CreatePullRequest(FinishFeatureData data) if (await provider.PullRequestExists(data.Repository.Info.RemoteUri, data.FeatureBranch, data.DefaultBranch)) { - _sysConsole.WriteLine("Pull/merge request already exists"); + _ansiConsole.WriteLine("Pull/merge request already exists"); return; } @@ -143,19 +153,21 @@ public async Task CreatePullRequest(FinishFeatureData data) try { - _sysConsole.WriteLine("Create pull/merge request"); + _ansiConsole.WriteLine("Create pull/merge request"); await provider.CreatePullRequestAsync(pullRequest).ConfigureAwait(false); - _sysConsole - .WriteLine("Pull/merge request created") - .WriteLine(); + _ansiConsole.WriteLines([ + "Pull/merge request created", + string.Empty + ]); } catch (CreatePullRequestFailedException e) { - _sysConsole - .WriteLineError(e.Message.Trim()) - .WriteLine(); + _ansiConsole.MarkupLines([ + e.Message.Trim().ToErrorMarkup(), + string.Empty + ]); throw new FeatureFinishFailedException("Create pull request failed", ReturnCodes.GeneralError); } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs index 68e9bbb..6dfc7b1 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs @@ -51,4 +51,24 @@ public static IAnsiConsole PrintCommitLog(this IAnsiConsole ansiConsole, IEnumer return ansiConsole; } + + public static IAnsiConsole WriteLines(this IAnsiConsole ansiConsole, IEnumerable lines) + { + foreach (var line in lines) + { + ansiConsole.WriteLine(line); + } + + return ansiConsole; + } + + public static IAnsiConsole MarkupLines(this IAnsiConsole ansiConsole, IEnumerable lines) + { + foreach (var line in lines) + { + ansiConsole.MarkupLine(line); + } + + return ansiConsole; + } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs new file mode 100644 index 0000000..ab8ea4f --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs @@ -0,0 +1,19 @@ +namespace CreativeCoders.GitTool.Cli.Commands.Shared; + +public static class StringExtensions +{ + public static string ToErrorMarkup(this string text) + { + return $"[red]{text}[/]"; + } + + public static string ToSuccessMarkup(this string text) + { + return $"[green]{text}[/]"; + } + + public static string ToWarningMarkup(this string text) + { + return $"[yellow]{text}[/]"; + } +} From f0cb27b983488567d37238b81e0c3c9641b9dc83 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:32:45 +0100 Subject: [PATCH 2/7] Refactor: Replace `ISysConsole` with `IAnsiConsole`, enforce `Ensure.NotNull` usage, and update command classes to standardize `_gitRepository` and `_ansiConsole` fields. --- .../FeatureGroup/Start/StartFeatureCommand.cs | 95 ++++++++++--------- .../FeatureGroup/Start/StartFeatureData.cs | 8 +- .../Create/CreateReleaseCommand.cs | 33 ++++--- .../Shared/GitToolPullCommand.cs | 12 +-- .../Shared/GitToolPushCommand.cs | 12 +-- .../Tool/Setup/SetupCommand.cs | 23 +++-- .../Tool/ShowConfig/ShowConfigCommand.cs | 13 ++- .../Program.cs | 1 - .../GitLabProjectIdTests.cs | 1 - 9 files changed, 107 insertions(+), 91 deletions(-) diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs index 39750bc..558ea4e 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs @@ -4,8 +4,9 @@ using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.SysConsole.Core.Abstractions; +using CreativeCoders.GitTool.Cli.Commands.Shared; using JetBrains.Annotations; +using Spectre.Console; using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; @@ -13,7 +14,7 @@ namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; [UsedImplicitly] [CliCommand([FeatureCommandGroup.Name, "start"], Description = "Start a new feature branch")] public class StartFeatureCommand( - ISysConsole sysConsole, + IAnsiConsole ansiConsole, IRepositoryConfigurations repositoryConfigurations, IGitToolPullCommand pullCommand, IGitRepository gitRepository) @@ -23,22 +24,25 @@ public class StartFeatureCommand( private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); private void PrintStartFeatureData(StartFeatureData data) { - _sysConsole - .WriteLine($"Create new feature branch '{data.FeatureBranch}' based on '{data.DefaultBranch}'") - .WriteLine(); + _ansiConsole.WriteLines([ + $"Create new feature branch '{data.FeatureBranch}' based on '{data.DefaultBranch}'", + string.Empty + ]); } private void CheckIfFeatureBranchExists(StartFeatureData data) { - var branch = gitRepository.Branches[data.FeatureBranch]; + var branch = _gitRepository.Branches[data.FeatureBranch]; if (branch != null) { - _sysConsole + _ansiConsole .WriteLine(); } @@ -50,78 +54,82 @@ private void CreateAndCheckOutFeatureBranch(StartFeatureOptions options, { var featureBranchName = repositoryConfiguration.GetFeatureBranchName(options.FeatureName); - _sysConsole.WriteLine($"Creating feature branch '{featureBranchName}' ..."); + _ansiConsole.WriteLine($"Creating feature branch '{featureBranchName}' ..."); - var featureBranch = gitRepository.Branches.CreateBranch(featureBranchName); + var featureBranch = _gitRepository.Branches.CreateBranch(featureBranchName); if (featureBranch == null) { - _sysConsole.WriteLineError("Feature branch could not be created"); + _ansiConsole.MarkupLine("Feature branch could not be created".ToErrorMarkup()); return; } - _sysConsole - .WriteLine("Feature branch created") - .WriteLine() - .WriteLine("Checking out feature branch..."); + _ansiConsole.WriteLines([ + "Feature branch created", + string.Empty, + "Checking out feature branch..." + ]); - var checkedOutBranch = gitRepository.Branches.CheckOut(featureBranch.Name.Canonical); + var checkedOutBranch = _gitRepository.Branches.CheckOut(featureBranch.Name.Canonical); if (checkedOutBranch == null) { - _sysConsole.WriteError("Feature Branch could not be checked out"); + _ansiConsole.Markup("Feature Branch could not be checked out".ToErrorMarkup()); return; } - _sysConsole - .WriteLine("Feature branch checked out") - .WriteLine(); + _ansiConsole.MarkupLines([ + "Feature branch checked out".ToSuccessMarkup(), + string.Empty + ]); } private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositoryConfiguration) { - var baseBranchName = repositoryConfiguration.GetDefaultBranchName(gitRepository.Info.MainBranch); + var baseBranchName = repositoryConfiguration.GetDefaultBranchName(_gitRepository.Info.MainBranch); if (string.IsNullOrEmpty(baseBranchName)) { - _sysConsole - .WriteLineError($"There seems to be no base branch '{baseBranchName}'") - .WriteLine() - .WriteLine("Existing branches:"); + _ansiConsole.MarkupLines([ + $"There seems to be no base branch '{baseBranchName}'".ToErrorMarkup(), + string.Empty, + "Existing branches:" + ]); - gitRepository.Branches.ForEach(branch => - _sysConsole.WriteLine($" {branch.Name.Friendly} -> {branch.TrackedBranch?.Name.Friendly}")); + _gitRepository.Branches.ForEach(branch => + _ansiConsole.WriteLine($" {branch.Name.Friendly} -> {branch.TrackedBranch?.Name.Friendly}")); return; } - _sysConsole.WriteLine($"Checkout base branch '{baseBranchName}'"); + _ansiConsole.WriteLine($"Checkout base branch '{baseBranchName}'"); - gitRepository.Branches.CheckOut(baseBranchName); + _gitRepository.Branches.CheckOut(baseBranchName); - _sysConsole - .WriteLine("Base branch checked out") - .WriteLine() - .WriteLine("Pulling from origin"); + _ansiConsole.WriteLines([ + "Base branch checked out", + string.Empty, + "Pulling from origin" + ]); - await _pullCommand.ExecuteAsync(gitRepository).ConfigureAwait(false); + await _pullCommand.ExecuteAsync(_gitRepository).ConfigureAwait(false); - gitRepository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); + _gitRepository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); } private StartFeatureData CreateData(StartFeatureOptions options) { - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + var configuration = _repositoryConfigurations.GetConfiguration(_gitRepository); return new StartFeatureData(configuration.GetFeatureBranchName(options.FeatureName), - configuration.GetDefaultBranchName(gitRepository.Info.MainBranch)); + configuration.GetDefaultBranchName(_gitRepository.Info.MainBranch)); } public async Task ExecuteAsync(StartFeatureOptions options) { - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + var configuration = _repositoryConfigurations.GetConfiguration(_gitRepository); var data = CreateData(options); @@ -135,13 +143,14 @@ public async Task ExecuteAsync(StartFeatureOptions options) if (options.PushAfterCreate) { - _sysConsole.WriteLine("Pushing feature branch to remote..."); + _ansiConsole.WriteLine("Pushing feature branch to remote..."); - gitRepository.Push(new GitPushOptions()); + _gitRepository.Push(new GitPushOptions()); - _sysConsole - .WriteLine("Feature branch pushed") - .WriteLine(); + _ansiConsole.WriteLines([ + "Feature branch pushed", + string.Empty + ]); } return ReturnCodes.Success; diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs index cd0b8db..1498e29 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs @@ -1,8 +1,10 @@ -namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; +using CreativeCoders.Core; + +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; public class StartFeatureData(string featureBranch, string defaultBranch) { - public string FeatureBranch { get; } = featureBranch; + public string FeatureBranch { get; } = Ensure.IsNotNullOrWhitespace(featureBranch); - public string DefaultBranch { get; } = defaultBranch; + public string DefaultBranch { get; } = Ensure.IsNotNullOrWhitespace(defaultBranch); } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs index 4361f5e..ca4bf1c 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs @@ -3,8 +3,8 @@ using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Branches; using CreativeCoders.GitTool.Base; -using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; +using Spectre.Console; namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; @@ -12,14 +12,16 @@ namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; [CliCommand([ReleaseCommandGroup.Name, "create"], Description = "Creates a release by creating a version tag")] public class CreateReleaseCommand( - ISysConsole sysConsole, + IAnsiConsole ansiConsole, IGitServiceProviders gitServiceProviders, IGitRepository gitRepository) : ICliCommand { private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); private async Task MergeDevelopToMain(IGitRepository repository, string mainBranchName, CreateReleaseOptions options) @@ -34,37 +36,38 @@ private async Task MergeDevelopToMain(IGitRepository repository, string mainBran public async Task ExecuteAsync(CreateReleaseOptions options) { - var mainBranchName = GitBranchNames.Local.GetCanonicalName(gitRepository.Info.MainBranch); + var mainBranchName = GitBranchNames.Local.GetCanonicalName(_gitRepository.Info.MainBranch); - if (gitRepository.Branches["develop"] != null) + if (_gitRepository.Branches["develop"] != null) { - _sysConsole.WriteLine( + _ansiConsole.WriteLine( $"Repository has a develop branch. So first a merge from develop -> {mainBranchName} must be done."); - await MergeDevelopToMain(gitRepository, mainBranchName, options); + await MergeDevelopToMain(_gitRepository, mainBranchName, options); } var tagName = $"v{options.Version}"; - _sysConsole.WriteLine($"Create tag '{tagName}'"); + _ansiConsole.WriteLine($"Create tag '{tagName}'"); - gitRepository.Branches.CheckOut(mainBranchName); + _gitRepository.Branches.CheckOut(mainBranchName); - gitRepository.Pull(); + _gitRepository.Pull(); - var versionTag = gitRepository.Tags.CreateTagWithMessage(tagName, mainBranchName, $"Version {options.Version}"); + var versionTag = + _gitRepository.Tags.CreateTagWithMessage(tagName, mainBranchName, $"Version {options.Version}"); if (options.PushAllTags) { - _sysConsole.WriteLine("Push all tags to remote"); + _ansiConsole.WriteLine("Push all tags to remote"); - gitRepository.Tags.PushAllTags(); + _gitRepository.Tags.PushAllTags(); } else { - _sysConsole.WriteLine($"Push tag '{versionTag.Name.Canonical}'"); + _ansiConsole.WriteLine($"Push tag '{versionTag.Name.Canonical}'"); - gitRepository.Tags.PushTag(versionTag); + _gitRepository.Tags.PushTag(versionTag); } return CommandResult.Success; diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs index c599576..dd15d6a 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs @@ -7,17 +7,11 @@ namespace CreativeCoders.GitTool.Cli.Commands.Shared; -public class GitToolPullCommand : IGitToolPullCommand +public class GitToolPullCommand(IAnsiConsole ansiConsole, ICml cml) : IGitToolPullCommand { - private readonly IAnsiConsole _ansiConsole; + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); - private readonly ICml _cml; - - public GitToolPullCommand(IAnsiConsole ansiConsole, ICml cml) - { - _ansiConsole = Ensure.NotNull(ansiConsole); - _cml = Ensure.NotNull(cml); - } + private readonly ICml _cml = Ensure.NotNull(cml); public Task ExecuteAsync(IGitRepository gitRepository) { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs index ef9671f..a645653 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs @@ -8,17 +8,11 @@ namespace CreativeCoders.GitTool.Cli.Commands.Shared; -public class GitToolPushCommand : IGitToolPushCommand +public class GitToolPushCommand(IAnsiConsole ansiConsole, ICml cml) : IGitToolPushCommand { - private readonly IAnsiConsole _ansiConsole; + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); - private readonly ICml _cml; - - public GitToolPushCommand(IAnsiConsole ansiConsole, ICml cml) - { - _ansiConsole = Ensure.NotNull(ansiConsole); - _cml = Ensure.NotNull(cml); - } + private readonly ICml _cml = Ensure.NotNull(cml); public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool confirmPush) => ExecuteAsync(gitRepository, createRemoteIsNotExists, confirmPush, false); diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs index d44a811..9a4bc86 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs @@ -1,4 +1,5 @@ using CreativeCoders.Cli.Core; +using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; @@ -16,23 +17,31 @@ public class SetupCommand( IRepositoryConfigurations repositoryConfigurations, IGitServiceProviders gitServiceProviders) : ICliCommand { + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly IGitRepository _gitRepository = Ensure.NotNull(gitRepository); + + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + + private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); + public async Task ExecuteAsync() { - var configuration = repositoryConfigurations.GetConfiguration(gitRepository); + var configuration = _repositoryConfigurations.GetConfiguration(_gitRepository); - ansiConsole.PrintBlock() + _ansiConsole.PrintBlock() .WriteLine() .WriteLine("Development branch (empty = no development branch)"); var developBranch = - await ansiConsole.PromptAsync( + await _ansiConsole.PromptAsync( new TextPrompt($"(Current value = '{configuration.DevelopBranch}'): ") { AllowEmpty = true }); configuration.DevelopBranch = developBranch ?? string.Empty; configuration.HasDevelopBranch = !string.IsNullOrEmpty(developBranch); - var featureBranchPrefix = await ansiConsole.PromptAsync(new TextPrompt( + var featureBranchPrefix = await _ansiConsole.PromptAsync(new TextPrompt( $"Prefix for feature branches (Empty = current value '{configuration.FeatureBranchPrefix}'): ") { AllowEmpty = true }); @@ -44,7 +53,7 @@ await ansiConsole.PromptAsync( var selectionPrompt = new SelectionPrompt(); var gitProviderName = - await ansiConsole.PromptAsync(selectionPrompt.AddChoices(gitServiceProviders.ProviderNames)); + await _ansiConsole.PromptAsync(selectionPrompt.AddChoices(_gitServiceProviders.ProviderNames)); if (!string.IsNullOrEmpty(gitProviderName)) { @@ -54,9 +63,9 @@ await ansiConsole.PromptAsync( var disableCertValidationPrompt = new ConfirmationPrompt("Disable certificate check (true/false): ") { DefaultValue = configuration.DisableCertificateValidation }; - configuration.DisableCertificateValidation = await ansiConsole.PromptAsync(disableCertValidationPrompt); + configuration.DisableCertificateValidation = await _ansiConsole.PromptAsync(disableCertValidationPrompt); - await repositoryConfigurations.SaveConfigurationAsync(gitRepository.Info.RemoteUri, configuration); + await _repositoryConfigurations.SaveConfigurationAsync(_gitRepository.Info.RemoteUri, configuration); return CommandResult.Success; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs index 1199a80..7360f40 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs @@ -1,4 +1,5 @@ using CreativeCoders.Cli.Core; +using CreativeCoders.Core; using CreativeCoders.Core.SysEnvironment; using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base.Configurations; @@ -13,13 +14,19 @@ public class ShowConfigCommand( IRepositoryConfigurations repositoryConfigurations, IGitRepositoryFactory gitRepositoryFactory) : ICliCommand { + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + + private readonly IGitRepositoryFactory _gitRepositoryFactory = Ensure.NotNull(gitRepositoryFactory); + public Task ExecuteAsync() { - using var repository = gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); + using var repository = _gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); - var configuration = repositoryConfigurations.GetConfiguration(repository); + var configuration = _repositoryConfigurations.GetConfiguration(repository); - ansiConsole.PrintBlock() + _ansiConsole.PrintBlock() .WriteLine() .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") .WriteLine() diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs index 9aa4b72..2ac1f01 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -8,7 +8,6 @@ using CreativeCoders.GitTool.Base.Output; using CreativeCoders.GitTool.Cli.Commands.FeatureGroup; using CreativeCoders.GitTool.Cli.Commands.Shared; -using CreativeCoders.GitTool.Cli.Commands.Tool; using CreativeCoders.GitTool.Cli.Commands.Tool.ShowConfig; using CreativeCoders.GitTool.GitHub; using CreativeCoders.GitTool.GitLab; diff --git a/tests/CreativeCoders.GitTool.GitLab.UnitTests/GitLabProjectIdTests.cs b/tests/CreativeCoders.GitTool.GitLab.UnitTests/GitLabProjectIdTests.cs index 89fc204..84de770 100644 --- a/tests/CreativeCoders.GitTool.GitLab.UnitTests/GitLabProjectIdTests.cs +++ b/tests/CreativeCoders.GitTool.GitLab.UnitTests/GitLabProjectIdTests.cs @@ -1,6 +1,5 @@ using System; using AwesomeAssertions; -using GitLabApiClient.Internal.Paths; using Xunit; namespace CreativeCoders.GitTool.GitLab.UnitTests; From efa4e241c36746d66446e40af1eb91e94a608b9f Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 15:36:58 +0100 Subject: [PATCH 3/7] Refactor: streamline null checks, simplify property initialization, and adjust branching logic across CLI and GitLab integrations. --- GitTools.sln.DotSettings | 1 + .../DefaultRepositoryConfigurations.cs | 2 +- .../DefaultGitServiceProviders.cs | 7 +------ .../GitCreatePullRequest.cs | 20 ++++++------------- .../FeatureGroup/Start/StartFeatureCommand.cs | 18 +++++++++-------- .../DefaultGitLabServiceProvider.cs | 9 +++------ 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/GitTools.sln.DotSettings b/GitTools.sln.DotSettings index 80f93a8..26ab1e7 100644 --- a/GitTools.sln.DotSettings +++ b/GitTools.sln.DotSettings @@ -1,4 +1,5 @@  + DO_NOT_SHOW ExplicitlyTyped True <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> diff --git a/source/GitTool/CreativeCoders.GitTool.Base/Configurations/DefaultRepositoryConfigurations.cs b/source/GitTool/CreativeCoders.GitTool.Base/Configurations/DefaultRepositoryConfigurations.cs index 1bd2ec5..5b04444 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/Configurations/DefaultRepositoryConfigurations.cs +++ b/source/GitTool/CreativeCoders.GitTool.Base/Configurations/DefaultRepositoryConfigurations.cs @@ -12,7 +12,7 @@ namespace CreativeCoders.GitTool.Base.Configurations; internal class DefaultRepositoryConfigurations : IRepositoryConfigurations { - private static readonly JsonSerializerOptions __jsonSerializerOptions = new JsonSerializerOptions() + private static readonly JsonSerializerOptions __jsonSerializerOptions = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; diff --git a/source/GitTool/CreativeCoders.GitTool.Base/DefaultGitServiceProviders.cs b/source/GitTool/CreativeCoders.GitTool.Base/DefaultGitServiceProviders.cs index 9c54960..2442656 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/DefaultGitServiceProviders.cs +++ b/source/GitTool/CreativeCoders.GitTool.Base/DefaultGitServiceProviders.cs @@ -50,12 +50,7 @@ public async Task GetServiceProviderAsync(IGitRepository gi var gitServiceProvider = await providerFactory.CreateProviderAsync(gitRepository).ConfigureAwait(false); - if (gitServiceProvider == null) - { - throw new GitServiceProviderNotFoundException(); - } - - return gitServiceProvider; + return gitServiceProvider ?? throw new GitServiceProviderNotFoundException(); } public IEnumerable ProviderNames => _providerFactories.Select(x => x.ProviderName); diff --git a/source/GitTool/CreativeCoders.GitTool.Base/GitCreatePullRequest.cs b/source/GitTool/CreativeCoders.GitTool.Base/GitCreatePullRequest.cs index cfb514b..c1998c8 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/GitCreatePullRequest.cs +++ b/source/GitTool/CreativeCoders.GitTool.Base/GitCreatePullRequest.cs @@ -3,23 +3,15 @@ namespace CreativeCoders.GitTool.Base; -public class GitCreatePullRequest +public class GitCreatePullRequest(Uri projectUrl, string title, string sourceBranch, string targetBranch) { - public GitCreatePullRequest(Uri projectUrl, string title, string sourceBranch, string targetBranch) - { - RepositoryUrl = Ensure.NotNull(projectUrl, nameof(projectUrl)); - Title = Ensure.IsNotNullOrWhitespace(title, nameof(title)); - SourceBranch = Ensure.IsNotNullOrWhitespace(sourceBranch, nameof(sourceBranch)); - TargetBranch = Ensure.IsNotNullOrWhitespace(targetBranch, nameof(targetBranch)); - } + public Uri RepositoryUrl { get; } = Ensure.NotNull(projectUrl); - public Uri RepositoryUrl { get; } + public string Title { get; } = Ensure.IsNotNullOrWhitespace(title); - public string Title { get; } + public string SourceBranch { get; } = Ensure.IsNotNullOrWhitespace(sourceBranch); - public string SourceBranch { get; } - - public string TargetBranch { get; } + public string TargetBranch { get; } = Ensure.IsNotNullOrWhitespace(targetBranch); public string? Description { get; set; } -} \ No newline at end of file +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs index 558ea4e..6af96d1 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs @@ -141,17 +141,19 @@ public async Task ExecuteAsync(StartFeatureOptions options) CreateAndCheckOutFeatureBranch(options, configuration); - if (options.PushAfterCreate) + if (!options.PushAfterCreate) { - _ansiConsole.WriteLine("Pushing feature branch to remote..."); + return ReturnCodes.Success; + } - _gitRepository.Push(new GitPushOptions()); + _ansiConsole.WriteLine("Pushing feature branch to remote..."); - _ansiConsole.WriteLines([ - "Feature branch pushed", - string.Empty - ]); - } + _gitRepository.Push(new GitPushOptions()); + + _ansiConsole.WriteLines([ + "Feature branch pushed", + string.Empty + ]); return ReturnCodes.Success; } diff --git a/source/GitTool/CreativeCoders.GitTool.GitLab/DefaultGitLabServiceProvider.cs b/source/GitTool/CreativeCoders.GitTool.GitLab/DefaultGitLabServiceProvider.cs index 1a058a4..0d0fa2a 100644 --- a/source/GitTool/CreativeCoders.GitTool.GitLab/DefaultGitLabServiceProvider.cs +++ b/source/GitTool/CreativeCoders.GitTool.GitLab/DefaultGitLabServiceProvider.cs @@ -35,12 +35,9 @@ public async Task CreatePullRequestAsync(GitCreatePullRequest gi var mergeRequest = await _gitLabClient.MergeRequests.CreateAsync(projectId, newMergeRequest); - if (mergeRequest == null) - { - throw new CreatePullRequestFailedException(); - } - - return new GitPullRequest(mergeRequest.WebUrl); + return mergeRequest == null + ? throw new CreatePullRequestFailedException() + : new GitPullRequest(mergeRequest.WebUrl); } public async Task PullRequestExists(Uri repositoryUrl, string sourceBranch, string targetBranch) From 5b6fd2351b79d6d0e20d34288953a46679353ec0 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:33:14 +0100 Subject: [PATCH 4/7] Upgrade dependencies to `CreativeCoders` 6.4.0 across all projects and add exception handling for repository initialization in CLI. --- build/Build.csproj | 2 +- .../CreativeCoders.Git.Abstractions.csproj | 2 +- .../CreativeCoders.Git.csproj | 2 +- .../CreativeCoders.GitTool.Base.csproj | 2 +- .../ReturnCodes.cs | 4 ++- ...CreativeCoders.GitTool.Cli.Commands.csproj | 4 +-- .../CreativeCoders.GitTool.Cli.GtApp.csproj | 2 +- .../Program.cs | 31 ++++++++++++------- .../CreativeCoders.GitTool.GitHub.csproj | 2 +- 9 files changed, 31 insertions(+), 20 deletions(-) diff --git a/build/Build.csproj b/build/Build.csproj index 3c06322..864d177 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj index 141d0a5..fb34f16 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj +++ b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj @@ -5,7 +5,7 @@ - + diff --git a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj index 635c87d..0714847 100644 --- a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj +++ b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj @@ -5,7 +5,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj index 870de7a..8035bf9 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Base/ReturnCodes.cs b/source/GitTool/CreativeCoders.GitTool.Base/ReturnCodes.cs index 89e365a..cba690c 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/ReturnCodes.cs +++ b/source/GitTool/CreativeCoders.GitTool.Base/ReturnCodes.cs @@ -9,4 +9,6 @@ public static class ReturnCodes public const int MergeConflicts = -3; public const int BranchHasUncommittedChanges = -4; -} \ No newline at end of file + + public const int NoGitRepositoryFound = -5; +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj index aa68630..ca14217 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj index f536ad2..07a7d97 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj @@ -10,7 +10,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs index 2ac1f01..51579ac 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -1,4 +1,5 @@ using CreativeCoders.Cli.Hosting; +using CreativeCoders.Cli.Hosting.Exceptions; using CreativeCoders.Cli.Hosting.Help; using CreativeCoders.Core.IO; using CreativeCoders.Core.SysEnvironment; @@ -58,22 +59,30 @@ private static void ConfigureGitRepository(IServiceCollection services) { services.TryAddSingleton(sp => { - var gitRepository = sp.GetRequiredService().OpenRepositoryFromCurrentDir(); + try + { + var gitRepository = sp.GetRequiredService().OpenRepositoryFromCurrentDir(); - var repositoryConfigurations = sp.GetRequiredService(); + var repositoryConfigurations = sp.GetRequiredService(); - var repoConfiguration = repositoryConfigurations.GetConfiguration(gitRepository); + var repoConfiguration = repositoryConfigurations.GetConfiguration(gitRepository); - if (repoConfiguration.DisableCertificateValidation) - { - gitRepository.CertificateCheck = (_, args) => + if (repoConfiguration.DisableCertificateValidation) { - args.IsValid = true; - return true; - }; + gitRepository.CertificateCheck = (_, args) => + { + args.IsValid = true; + return true; + }; + } + + return gitRepository; + } + catch (Exception e) + { + throw new CliCommandAbortException($"Error opening git repository: {e.Message}", + ReturnCodes.NoGitRepositoryFound, e); } - - return gitRepository; }); } diff --git a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj index 950c8fc..22bc476 100644 --- a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj +++ b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj @@ -5,7 +5,7 @@ - + From 3ac5a930816f5e231a13f29e79c5d61481167910 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:39:29 +0100 Subject: [PATCH 5/7] Remove `StringExtensions` and obsolete `AnsiConsoleExtensions` methods; upgrade `CreativeCoders` dependencies to 6.5.0. --- build/Build.csproj | 2 +- .../CreativeCoders.Git.Abstractions.csproj | 2 +- .../CreativeCoders.Git.csproj | 2 +- .../CreativeCoders.GitTool.Base.csproj | 2 +- ...CreativeCoders.GitTool.Cli.Commands.csproj | 4 +- .../FeatureGroup/Finish/FinishFeatureSteps.cs | 60 ++++++------------- .../FeatureGroup/Start/StartFeatureCommand.cs | 37 +++--------- .../Shared/AnsiConsoleExtensions.cs | 20 ------- .../Shared/StringExtensions.cs | 19 ------ .../CreativeCoders.GitTool.Cli.GtApp.csproj | 2 +- .../CreativeCoders.GitTool.GitHub.csproj | 2 +- 11 files changed, 34 insertions(+), 118 deletions(-) delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs diff --git a/build/Build.csproj b/build/Build.csproj index 864d177..7ea113f 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj index fb34f16..dced856 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj +++ b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj @@ -5,7 +5,7 @@ - + diff --git a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj index 0714847..0457a51 100644 --- a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj +++ b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj @@ -5,7 +5,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj index 8035bf9..2a3f55e 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj index ca14217..7fd2f25 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs index dfbea7c..6307fe7 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs @@ -3,7 +3,7 @@ using CreativeCoders.Git.Abstractions.Commits; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Exceptions; -using CreativeCoders.GitTool.Cli.Commands.Shared; +using CreativeCoders.SysConsole.Core; using Spectre.Console; using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; @@ -29,19 +29,15 @@ public void UpdateFeatureBranch(FinishFeatureData data) if (data.Repository.HasUncommittedChanges(true)) { - _ansiConsole.MarkupLines([ + _ansiConsole.MarkupLines( "Feature branch has uncommitted changes. Please commit or revert and try again".ToErrorMarkup(), - string.Empty - ]); + string.Empty); throw new FeatureFinishFailedException("Feature branch has uncommitted changes", ReturnCodes.BranchHasUncommittedChanges); } - _ansiConsole.WriteLines([ - "Feature branch checked out", - string.Empty - ]); + _ansiConsole.WriteLines("Feature branch checked out", string.Empty); if (data.Repository.Branches[data.FeatureBranch]?.TrackedBranch == null) { @@ -57,19 +53,14 @@ public void UpdateFeatureBranch(FinishFeatureData data) if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _ansiConsole.MarkupLines([ - "Pull feature branch updates from remote caused merge conflicts".ToErrorMarkup(), - "Resolve conflicts and try again".ToErrorMarkup() - ]); + _ansiConsole.MarkupLines("Pull feature branch updates from remote caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup()); throw new FeatureFinishFailedException("Merge feature branch from remote into local caused merge conflicts", ReturnCodes.MergeConflicts); } - _ansiConsole.WriteLines([ - "Feature branch updates pulled from remote", - string.Empty - ]); + _ansiConsole.WriteLines("Feature branch updates pulled from remote", string.Empty); } public void MergeDefaultBranch(FinishFeatureData data) @@ -78,38 +69,27 @@ public void MergeDefaultBranch(FinishFeatureData data) data.Repository.Branches.CheckOut(data.DefaultBranch); - _ansiConsole.WriteLines([ - "Default branch checked out", - string.Empty, - "Pull default branch updates from remote" - ]); + _ansiConsole.WriteLines("Default branch checked out", string.Empty, "Pull default branch updates from remote"); var mergeResult = data.Repository.Pull(); if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _ansiConsole.MarkupLines([ - "Pull default branch updates from remote caused merge conflicts".ToErrorMarkup(), - "Resolve conflicts and try again".ToErrorMarkup() - ]); + _ansiConsole.MarkupLines("Pull default branch updates from remote caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup()); throw new FeatureFinishFailedException("Merge default branch from remote into local caused merge conflicts", ReturnCodes.MergeConflicts); } - _ansiConsole.WriteLines([ - "Default branch updates pulled from remote", - string.Empty - ]); + _ansiConsole.WriteLines("Default branch updates pulled from remote", string.Empty); mergeResult = data.Repository.Merge(data.DefaultBranch, data.FeatureBranch, new GitMergeOptions()); if (mergeResult.MergeStatus == GitMergeStatus.Conflicts) { - _ansiConsole.MarkupLines([ - "Merge default branch to feature branch caused merge conflicts".ToErrorMarkup(), - "Resolve conflicts and try again".ToErrorMarkup() - ]); + _ansiConsole.MarkupLines("Merge default branch to feature branch caused merge conflicts".ToErrorMarkup(), + "Resolve conflicts and try again".ToErrorMarkup()); throw new FeatureFinishFailedException("Merge default branch to feature branch caused merge conflicts", ReturnCodes.MergeConflicts); @@ -128,10 +108,7 @@ public async Task PushFeatureBranch(FinishFeatureData data) await _pushCommand.ExecuteAsync(data.Repository, true, false).ConfigureAwait(false); } - _ansiConsole.WriteLines([ - "Feature branch pushed to remote", - string.Empty - ]); + _ansiConsole.WriteLines("Feature branch pushed to remote", string.Empty); } public async Task CreatePullRequest(FinishFeatureData data) @@ -157,17 +134,14 @@ public async Task CreatePullRequest(FinishFeatureData data) await provider.CreatePullRequestAsync(pullRequest).ConfigureAwait(false); - _ansiConsole.WriteLines([ + _ansiConsole.WriteLines( "Pull/merge request created", string.Empty - ]); + ); } catch (CreatePullRequestFailedException e) { - _ansiConsole.MarkupLines([ - e.Message.Trim().ToErrorMarkup(), - string.Empty - ]); + _ansiConsole.MarkupLines(e.Message.Trim().ToErrorMarkup(), string.Empty); throw new FeatureFinishFailedException("Create pull request failed", ReturnCodes.GeneralError); } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs index 6af96d1..90576bc 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs @@ -4,7 +4,7 @@ using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Cli.Commands.Shared; +using CreativeCoders.SysConsole.Core; using JetBrains.Annotations; using Spectre.Console; using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; @@ -30,10 +30,8 @@ public class StartFeatureCommand( private void PrintStartFeatureData(StartFeatureData data) { - _ansiConsole.WriteLines([ - $"Create new feature branch '{data.FeatureBranch}' based on '{data.DefaultBranch}'", - string.Empty - ]); + _ansiConsole.WriteLines($"Create new feature branch '{data.FeatureBranch}' based on '{data.DefaultBranch}'", + string.Empty); } private void CheckIfFeatureBranchExists(StartFeatureData data) @@ -65,11 +63,7 @@ private void CreateAndCheckOutFeatureBranch(StartFeatureOptions options, return; } - _ansiConsole.WriteLines([ - "Feature branch created", - string.Empty, - "Checking out feature branch..." - ]); + _ansiConsole.WriteLines("Feature branch created", string.Empty, "Checking out feature branch..."); var checkedOutBranch = _gitRepository.Branches.CheckOut(featureBranch.Name.Canonical); @@ -80,10 +74,7 @@ private void CreateAndCheckOutFeatureBranch(StartFeatureOptions options, return; } - _ansiConsole.MarkupLines([ - "Feature branch checked out".ToSuccessMarkup(), - string.Empty - ]); + _ansiConsole.MarkupLines("Feature branch checked out".ToSuccessMarkup(), string.Empty); } private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositoryConfiguration) @@ -92,11 +83,8 @@ private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositor if (string.IsNullOrEmpty(baseBranchName)) { - _ansiConsole.MarkupLines([ - $"There seems to be no base branch '{baseBranchName}'".ToErrorMarkup(), - string.Empty, - "Existing branches:" - ]); + _ansiConsole.MarkupLines($"There seems to be no base branch '{baseBranchName}'".ToErrorMarkup(), + string.Empty, "Existing branches:"); _gitRepository.Branches.ForEach(branch => _ansiConsole.WriteLine($" {branch.Name.Friendly} -> {branch.TrackedBranch?.Name.Friendly}")); @@ -108,11 +96,7 @@ private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositor _gitRepository.Branches.CheckOut(baseBranchName); - _ansiConsole.WriteLines([ - "Base branch checked out", - string.Empty, - "Pulling from origin" - ]); + _ansiConsole.WriteLines("Base branch checked out", string.Empty, "Pulling from origin"); await _pullCommand.ExecuteAsync(_gitRepository).ConfigureAwait(false); @@ -150,10 +134,7 @@ public async Task ExecuteAsync(StartFeatureOptions options) _gitRepository.Push(new GitPushOptions()); - _ansiConsole.WriteLines([ - "Feature branch pushed", - string.Empty - ]); + _ansiConsole.WriteLines("Feature branch pushed", string.Empty); return ReturnCodes.Success; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs index 6dfc7b1..68e9bbb 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs @@ -51,24 +51,4 @@ public static IAnsiConsole PrintCommitLog(this IAnsiConsole ansiConsole, IEnumer return ansiConsole; } - - public static IAnsiConsole WriteLines(this IAnsiConsole ansiConsole, IEnumerable lines) - { - foreach (var line in lines) - { - ansiConsole.WriteLine(line); - } - - return ansiConsole; - } - - public static IAnsiConsole MarkupLines(this IAnsiConsole ansiConsole, IEnumerable lines) - { - foreach (var line in lines) - { - ansiConsole.MarkupLine(line); - } - - return ansiConsole; - } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs deleted file mode 100644 index ab8ea4f..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/StringExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace CreativeCoders.GitTool.Cli.Commands.Shared; - -public static class StringExtensions -{ - public static string ToErrorMarkup(this string text) - { - return $"[red]{text}[/]"; - } - - public static string ToSuccessMarkup(this string text) - { - return $"[green]{text}[/]"; - } - - public static string ToWarningMarkup(this string text) - { - return $"[yellow]{text}[/]"; - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj index 07a7d97..959a8ab 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj @@ -10,7 +10,7 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj index 22bc476..f078473 100644 --- a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj +++ b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj @@ -5,7 +5,7 @@ - + From 27f324f11e418e2ea4f973a3ea0f3576b96f38d9 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:48:00 +0100 Subject: [PATCH 6/7] Refactor: simplify null checks by removing parameter names from `Ensure.NotNull` calls and convert fields to properties in `GitMergeOptions`. --- .../Git/CreativeCoders.Git.Abstractions/GitMergeOptions.cs | 4 ++-- .../Pushes/GitPushUpdate.cs | 7 ++++--- source/Git/CreativeCoders.Git/Branches/GitBranch.cs | 4 ++-- source/Git/CreativeCoders.Git/Commits/GitCommit.cs | 6 +++--- source/Git/CreativeCoders.Git/Commits/GitCommitLog.cs | 4 ++-- source/Git/CreativeCoders.Git/Common/GitSignature.cs | 2 +- source/Git/CreativeCoders.Git/Diffs/GitDiffer.cs | 4 ++-- source/Git/CreativeCoders.Git/Diffs/GitTreeChanges.cs | 4 ++-- source/Git/CreativeCoders.Git/Diffs/GitTreeEntryChanges.cs | 4 ++-- source/Git/CreativeCoders.Git/Objects/GitObjectId.cs | 4 ++-- source/Git/CreativeCoders.Git/RefSpecs/GitRefSpec.cs | 4 ++-- source/Git/CreativeCoders.Git/References/GitReference.cs | 4 ++-- .../References/GitReferenceCollection.cs | 4 ++-- .../Git/CreativeCoders.Git/Remotes/GitRemoteCollection.cs | 4 ++-- source/Git/CreativeCoders.Git/Tags/GitTag.cs | 4 ++-- 15 files changed, 32 insertions(+), 31 deletions(-) diff --git a/source/Git/CreativeCoders.Git.Abstractions/GitMergeOptions.cs b/source/Git/CreativeCoders.Git.Abstractions/GitMergeOptions.cs index a804723..b58ecd9 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/GitMergeOptions.cs +++ b/source/Git/CreativeCoders.Git.Abstractions/GitMergeOptions.cs @@ -8,13 +8,13 @@ public class GitMergeOptions /// /// Similarity to consider a file renamed. /// - public int RenameThreshold = 50; + public int RenameThreshold { get; set; } = 50; /// /// Maximum similarity sources to examine (overrides /// 'merge.renameLimit' config (default 200) /// - public int TargetLimit = 200; + public int TargetLimit { get; set; } = 200; public GitFastForwardStrategy FastForwardStrategy { get; set; } diff --git a/source/Git/CreativeCoders.Git.Abstractions/Pushes/GitPushUpdate.cs b/source/Git/CreativeCoders.Git.Abstractions/Pushes/GitPushUpdate.cs index d899f7c..6957259 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/Pushes/GitPushUpdate.cs +++ b/source/Git/CreativeCoders.Git.Abstractions/Pushes/GitPushUpdate.cs @@ -5,11 +5,12 @@ namespace CreativeCoders.Git.Abstractions.Pushes; public class GitPushUpdate { - public GitPushUpdate(IGitObjectId sourceObjectId, string sourceRefName, IGitObjectId destinationObjectId, string destinationRefName) + public GitPushUpdate(IGitObjectId sourceObjectId, string sourceRefName, IGitObjectId destinationObjectId, + string destinationRefName) { - SourceObjectId = Ensure.NotNull(sourceObjectId, nameof(sourceObjectId)); + SourceObjectId = Ensure.NotNull(sourceObjectId); SourceRefName = sourceRefName; - DestinationObjectId = Ensure.NotNull(destinationObjectId, nameof(destinationObjectId)); + DestinationObjectId = Ensure.NotNull(destinationObjectId); DestinationRefName = destinationRefName; } diff --git a/source/Git/CreativeCoders.Git/Branches/GitBranch.cs b/source/Git/CreativeCoders.Git/Branches/GitBranch.cs index 046c177..fb6240c 100644 --- a/source/Git/CreativeCoders.Git/Branches/GitBranch.cs +++ b/source/Git/CreativeCoders.Git/Branches/GitBranch.cs @@ -11,7 +11,7 @@ public class GitBranch : ComparableObject, IGitBranch internal GitBranch(Branch branch) { - _branch = Ensure.NotNull(branch, nameof(branch)); + _branch = Ensure.NotNull(branch); Name = new ReferenceName(branch.CanonicalName); Tip = GitCommit.From(branch.Tip); @@ -43,4 +43,4 @@ internal GitBranch(Branch branch) public IGitCommitLog? Commits { get; } public static implicit operator Branch(GitBranch branch) => branch._branch; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Commits/GitCommit.cs b/source/Git/CreativeCoders.Git/Commits/GitCommit.cs index c49d151..9138f64 100644 --- a/source/Git/CreativeCoders.Git/Commits/GitCommit.cs +++ b/source/Git/CreativeCoders.Git/Commits/GitCommit.cs @@ -4,13 +4,13 @@ namespace CreativeCoders.Git.Commits; -public class GitCommit : Objects.GitObject, IGitCommit +public sealed class GitCommit : Objects.GitObject, IGitCommit { private readonly Commit _commit; internal GitCommit(Commit commit) : base(commit) { - _commit = Ensure.NotNull(commit, nameof(commit)); + _commit = Ensure.NotNull(commit); Parents = _commit.Parents.Select(x => new GitCommit(x)); Author = new GitSignature(_commit.Author); @@ -43,4 +43,4 @@ public int CompareTo(IGitCommit? other) public string Message => _commit.Message; public static implicit operator Commit(GitCommit commit) => commit._commit; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Commits/GitCommitLog.cs b/source/Git/CreativeCoders.Git/Commits/GitCommitLog.cs index c70601d..7abaf0f 100644 --- a/source/Git/CreativeCoders.Git/Commits/GitCommitLog.cs +++ b/source/Git/CreativeCoders.Git/Commits/GitCommitLog.cs @@ -8,7 +8,7 @@ public class GitCommitLog : IGitCommitLog internal GitCommitLog(ICommitLog commitLog) { - _commitLog = Ensure.NotNull(commitLog, nameof(commitLog)); + _commitLog = Ensure.NotNull(commitLog); } internal static GitCommitLog? From(ICommitLog? commitLog) @@ -33,4 +33,4 @@ public IEnumerable QueryBy(GitCommitFilter commitFilter) { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Common/GitSignature.cs b/source/Git/CreativeCoders.Git/Common/GitSignature.cs index f218f01..ea39fad 100644 --- a/source/Git/CreativeCoders.Git/Common/GitSignature.cs +++ b/source/Git/CreativeCoders.Git/Common/GitSignature.cs @@ -8,7 +8,7 @@ public class GitSignature : IGitSignature public GitSignature(Signature signature) { - _signature = Ensure.NotNull(signature, nameof(signature)); + _signature = Ensure.NotNull(signature); } public DateTimeOffset When => _signature.When; diff --git a/source/Git/CreativeCoders.Git/Diffs/GitDiffer.cs b/source/Git/CreativeCoders.Git/Diffs/GitDiffer.cs index 07dbafd..4198bda 100644 --- a/source/Git/CreativeCoders.Git/Diffs/GitDiffer.cs +++ b/source/Git/CreativeCoders.Git/Diffs/GitDiffer.cs @@ -8,7 +8,7 @@ public class GitDiffer : IGitDiffer public GitDiffer(Diff diff) { - _diff = Ensure.NotNull(diff, nameof(diff)); + _diff = Ensure.NotNull(diff); } public IGitTreeChanges Compare() @@ -30,4 +30,4 @@ public IGitTreeChanges Compare(IEnumerable paths, bool includeUntracked) { return new GitTreeChanges(_diff.Compare(paths, includeUntracked)); } -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Diffs/GitTreeChanges.cs b/source/Git/CreativeCoders.Git/Diffs/GitTreeChanges.cs index ac9f52f..02ae324 100644 --- a/source/Git/CreativeCoders.Git/Diffs/GitTreeChanges.cs +++ b/source/Git/CreativeCoders.Git/Diffs/GitTreeChanges.cs @@ -8,7 +8,7 @@ public sealed class GitTreeChanges : IGitTreeChanges internal GitTreeChanges(TreeChanges treeChanges) { - _treeChanges = Ensure.NotNull(treeChanges, nameof(treeChanges)); + _treeChanges = Ensure.NotNull(treeChanges); } public IEnumerator GetEnumerator() @@ -53,4 +53,4 @@ public IEnumerable Conflicted => ToGitTreeEntryChanges(_treeChanges.Conflicted); public int Count => _treeChanges.Count; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Diffs/GitTreeEntryChanges.cs b/source/Git/CreativeCoders.Git/Diffs/GitTreeEntryChanges.cs index 6bd5eb5..cf2e754 100644 --- a/source/Git/CreativeCoders.Git/Diffs/GitTreeEntryChanges.cs +++ b/source/Git/CreativeCoders.Git/Diffs/GitTreeEntryChanges.cs @@ -11,7 +11,7 @@ public class GitTreeEntryChanges : IGitTreeEntryChanges internal GitTreeEntryChanges(TreeEntryChanges treeEntryChanges) { - _treeEntryChanges = Ensure.NotNull(treeEntryChanges, nameof(treeEntryChanges)); + _treeEntryChanges = Ensure.NotNull(treeEntryChanges); Mode = treeEntryChanges.Mode.ToGitEntryMode(); Oid = new GitObjectId(treeEntryChanges.Oid); @@ -37,4 +37,4 @@ internal GitTreeEntryChanges(TreeEntryChanges treeEntryChanges) public IGitObjectId OldOid { get; } public bool OldExists => _treeEntryChanges.OldExists; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Objects/GitObjectId.cs b/source/Git/CreativeCoders.Git/Objects/GitObjectId.cs index 747f38e..a2252ed 100644 --- a/source/Git/CreativeCoders.Git/Objects/GitObjectId.cs +++ b/source/Git/CreativeCoders.Git/Objects/GitObjectId.cs @@ -8,7 +8,7 @@ public class GitObjectId : ComparableObject, IGitObje internal GitObjectId(ObjectId objectId) { - _objectId = Ensure.NotNull(objectId, nameof(objectId)); + _objectId = Ensure.NotNull(objectId); } public GitObjectId(string sha) : this(new ObjectId(sha)) @@ -25,4 +25,4 @@ static GitObjectId() public string Sha => _objectId.Sha; public string ToString(int prefixLength) => _objectId.ToString(prefixLength); -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/RefSpecs/GitRefSpec.cs b/source/Git/CreativeCoders.Git/RefSpecs/GitRefSpec.cs index 96a05db..348ef5f 100644 --- a/source/Git/CreativeCoders.Git/RefSpecs/GitRefSpec.cs +++ b/source/Git/CreativeCoders.Git/RefSpecs/GitRefSpec.cs @@ -9,7 +9,7 @@ public class GitRefSpec : ComparableObject, IGitRefSpec internal GitRefSpec(RefSpec refSpec) { - _refSpec = Ensure.NotNull(refSpec, nameof(refSpec)); + _refSpec = Ensure.NotNull(refSpec); } static GitRefSpec() => InitComparableObject(x => x.Specification); @@ -25,4 +25,4 @@ internal GitRefSpec(RefSpec refSpec) public override string ToString() => Specification; public static implicit operator RefSpec(GitRefSpec refSpec) => refSpec._refSpec; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/References/GitReference.cs b/source/Git/CreativeCoders.Git/References/GitReference.cs index 81291cb..5ec2d22 100644 --- a/source/Git/CreativeCoders.Git/References/GitReference.cs +++ b/source/Git/CreativeCoders.Git/References/GitReference.cs @@ -11,7 +11,7 @@ public class GitReference : ComparableObject, IGitR internal GitReference(Reference reference) { - _reference = Ensure.NotNull(reference, nameof(reference)); + _reference = Ensure.NotNull(reference); Name = new ReferenceName(reference.CanonicalName); @@ -37,4 +37,4 @@ internal GitReference(Reference reference) public IGitObjectId? ReferenceTargetId { get; } public static implicit operator Reference(GitReference reference) => reference._reference; -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/References/GitReferenceCollection.cs b/source/Git/CreativeCoders.Git/References/GitReferenceCollection.cs index 7c2109a..8b72f87 100644 --- a/source/Git/CreativeCoders.Git/References/GitReferenceCollection.cs +++ b/source/Git/CreativeCoders.Git/References/GitReferenceCollection.cs @@ -12,7 +12,7 @@ public class GitReferenceCollection : IGitReferenceCollection internal GitReferenceCollection(ReferenceCollection referenceCollection) { - _referenceCollection = Ensure.NotNull(referenceCollection, nameof(referenceCollection)); + _referenceCollection = Ensure.NotNull(referenceCollection); } public IEnumerator GetEnumerator() @@ -39,4 +39,4 @@ public void UpdateTarget(IGitReference directRef, IGitObjectId targetId) public IEnumerable FromGlob(string prefix) => _referenceCollection.FromGlob(prefix).Select(x => new GitReference(x)); -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Remotes/GitRemoteCollection.cs b/source/Git/CreativeCoders.Git/Remotes/GitRemoteCollection.cs index d5d80ed..9005141 100644 --- a/source/Git/CreativeCoders.Git/Remotes/GitRemoteCollection.cs +++ b/source/Git/CreativeCoders.Git/Remotes/GitRemoteCollection.cs @@ -8,7 +8,7 @@ public class GitRemoteCollection : IGitRemoteCollection public GitRemoteCollection(RemoteCollection remoteCollection) { - _remoteCollection = Ensure.NotNull(remoteCollection, nameof(remoteCollection)); + _remoteCollection = Ensure.NotNull(remoteCollection); } public IEnumerator GetEnumerator() @@ -20,4 +20,4 @@ IEnumerator IEnumerable.GetEnumerator() } public IGitRemote? this[string name] => GitRemote.From(_remoteCollection[name]); -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/Tags/GitTag.cs b/source/Git/CreativeCoders.Git/Tags/GitTag.cs index a48e280..d356f2d 100644 --- a/source/Git/CreativeCoders.Git/Tags/GitTag.cs +++ b/source/Git/CreativeCoders.Git/Tags/GitTag.cs @@ -11,7 +11,7 @@ public class GitTag : ComparableObject, IGitTag internal GitTag(Tag tag) { - _tag = Ensure.NotNull(tag, nameof(tag)); + _tag = Ensure.NotNull(tag); Name = new ReferenceName(_tag.CanonicalName); } @@ -35,4 +35,4 @@ internal GitTag(Tag tag) } public static implicit operator Tag(GitTag tag) => tag._tag; -} \ No newline at end of file +} From 37eaeecf8ec3c79e97904fc5806ae9d8a0bc5852 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 7 Feb 2026 11:40:50 +0100 Subject: [PATCH 7/7] Refactor: replace `default` with `null` for `credentialsNameSpace` parameter in `Create` method of `DefaultGcmCoreCredentialStore`. --- .../DefaultGcmCoreCredentialStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Git/CreativeCoders.Git.Auth.CredentialManagerCore/DefaultGcmCoreCredentialStore.cs b/source/Git/CreativeCoders.Git.Auth.CredentialManagerCore/DefaultGcmCoreCredentialStore.cs index 194b00a..3ded097 100644 --- a/source/Git/CreativeCoders.Git.Auth.CredentialManagerCore/DefaultGcmCoreCredentialStore.cs +++ b/source/Git/CreativeCoders.Git.Auth.CredentialManagerCore/DefaultGcmCoreCredentialStore.cs @@ -6,7 +6,7 @@ namespace CreativeCoders.Git.Auth.CredentialManagerCore; [ExcludeFromCodeCoverage] internal class DefaultGcmCoreCredentialStore : IGcmCoreCredentialStore { - public ICredentialStore Create(string? credentialsNameSpace = default) + public ICredentialStore Create(string? credentialsNameSpace = null) { return CredentialManager.Create(credentialsNameSpace); }