From 586d3d358fc82bf4e03aa53743835e815ce17d23 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 15:59:05 +0100 Subject: [PATCH 1/7] Introduce CLI application and commands for GitTool - Add `CreativeCoders.GitTool.Cli.App` project for GitTool's CLI application. - Add `CreativeCoders.GitTool.Cli.Commands` project to host commands. - Implement `ShowConfigCommand` to display repository configuration. - Integrate GitHub and GitLab tools into the CLI. - Update solution and build configuration to include new CLI projects. - Upgrade dependencies to `CreativeCoders.Core 6.2.0`. --- GitTools.sln | 17 +++++ build/Build.csproj | 2 +- build/BuildContext.cs | 4 +- ...CreativeCoders.GitTool.Cli.Commands.csproj | 25 +++++++ .../Tool/ShowConfigCommand.cs | 35 +++++++++ .../CreativeCoders.Git.Abstractions.csproj | 4 +- .../IGitRepositoryFactory.cs | 2 +- .../CreativeCoders.Git.csproj | 6 +- ...iveCoders.GitTool.Commands.Branches.csproj | 8 +- ...iveCoders.GitTool.Commands.Features.csproj | 6 +- ...iveCoders.GitTool.Commands.Releases.csproj | 2 +- ...reativeCoders.GitTool.Commands.Tool.csproj | 2 +- .../CreativeCoders.GitTool.Base.csproj | 8 +- .../CreativeCoders.GitTool.Cli.App.csproj | 23 ++++++ .../CreativeCoders.GitTool.Cli.App/Program.cs | 73 +++++++++++++++++++ .../CreativeCoders.GitTool.Cli.csproj | 8 +- .../CreativeCoders.GitTool.GitHub.csproj | 8 +- ...uth.CredentialManagerCore.UnitTests.csproj | 12 +-- .../CreativeCoders.Git.UnitTests.csproj | 10 +-- ...tiveCoders.GitTool.GitHub.UnitTests.csproj | 10 +-- ...tiveCoders.GitTool.GitLab.UnitTests.csproj | 10 +-- 21 files changed, 224 insertions(+), 51 deletions(-) create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs diff --git a/GitTools.sln b/GitTools.sln index 7245986..77bc7ac 100644 --- a/GitTools.sln +++ b/GitTools.sln @@ -88,6 +88,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DE982092 build.sh = build.sh EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cli", "Cli", "{D65676E3-6820-464B-8493-597E3E1DCD98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.App", "source\GitTool\CreativeCoders.GitTool.Cli.App\CreativeCoders.GitTool.Cli.App.csproj", "{46156AAB-B9F6-4C99-AD0A-9F370DB87679}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.Commands", "source\CreativeCoders.GitTool.Cli.Commands\CreativeCoders.GitTool.Cli.Commands.csproj", "{AAF48CD8-DD38-4925-B0AD-798416312825}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -160,6 +166,14 @@ Global {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Release|Any CPU.Build.0 = Release|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.Build.0 = Release|Any CPU + {AAF48CD8-DD38-4925-B0AD-798416312825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAF48CD8-DD38-4925-B0AD-798416312825}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAF48CD8-DD38-4925-B0AD-798416312825}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAF48CD8-DD38-4925-B0AD-798416312825}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -187,6 +201,9 @@ Global {06510226-737C-4300-92A5-3FE3C5E4D6A4} = {E4F28808-C129-4AE9-8454-08EAB02D7E7F} {E91F4387-0278-43C4-AE97-E9C54E414C41} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} {DE982092-6508-4062-99D5-6A6EE9ECB81F} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} + {D65676E3-6820-464B-8493-597E3E1DCD98} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} + {46156AAB-B9F6-4C99-AD0A-9F370DB87679} = {D65676E3-6820-464B-8493-597E3E1DCD98} + {AAF48CD8-DD38-4925-B0AD-798416312825} = {D65676E3-6820-464B-8493-597E3E1DCD98} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D38E5978-8FB3-474B-BDCB-18853E21A429} diff --git a/build/Build.csproj b/build/Build.csproj index fc602e8..3c06322 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -8,7 +8,7 @@ - + diff --git a/build/BuildContext.cs b/build/BuildContext.cs index 07eb0f0..8cf8f29 100644 --- a/build/BuildContext.cs +++ b/build/BuildContext.cs @@ -35,9 +35,9 @@ public class BuildContext(ICakeContext context) public DirectoryPath PublishOutputDir => ArtifactsDir.Combine("published"); - private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli"; + private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli.App"; - private const string CliProjectFile = "CreativeCoders.GitTool.Cli.csproj"; + private const string CliProjectFile = "CreativeCoders.GitTool.Cli.App.csproj"; public IEnumerable PublishingItems => [ diff --git a/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj new file mode 100644 index 0000000..baddc3d --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -0,0 +1,25 @@ + + + + net10.0 + enable + enable + + + + + + + + + + + + + + + + + + + diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs new file mode 100644 index 0000000..e06f3a4 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs @@ -0,0 +1,35 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core.SysEnvironment; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.SysConsole.Core; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Tool; + +[CliCommand(["showconfig"], Description = "Shows the current repository configuration")] +public class ShowConfigCommand( + IAnsiConsole console, + IRepositoryConfigurations repositoryConfigurations, + IGitRepositoryFactory gitRepositoryFactory) : ICliCommand +{ + public Task ExecuteAsync() + { + using var repository = gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); + + var configuration = repositoryConfigurations.GetConfiguration(repository); + + console.PrintBlock() + .WriteLine() + .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") + .WriteLine() + .WriteLine($"HasDevelopBranch: {configuration.HasDevelopBranch}") + .WriteLine($"DevelopBranch: {configuration.DevelopBranch}") + .WriteLine($"FeatureBranchPrefix: {configuration.FeatureBranchPrefix}") + .WriteLine($"GitServiceProviderName: {configuration.GitServiceProviderName}") + .WriteLine($"DisableCertificateValidation: {configuration.DisableCertificateValidation}") + .WriteLine(); + + return Task.FromResult(CommandResult.Success); + } +} diff --git a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj index 1576e74..141d0a5 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj +++ b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs b/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs index fc8039e..5d3c94a 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs +++ b/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs @@ -8,4 +8,4 @@ public interface IGitRepositoryFactory IGitRepository OpenRepository(string? path); IGitRepository OpenRepositoryFromCurrentDir(); -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj index c2d4292..635c87d 100644 --- a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj +++ b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj @@ -5,9 +5,9 @@ - - - + + + diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj index f751023..269047e 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj +++ b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj index 44723ad..9e87b32 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj +++ b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj @@ -5,9 +5,9 @@ - - - + + + diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj index b7a1c9e..f1f25a3 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj +++ b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj @@ -5,7 +5,7 @@ - + diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj index 13b2926..6a65ae6 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj +++ b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.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 f8a0507..870de7a 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj new file mode 100644 index 0000000..ca68d1e --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj @@ -0,0 +1,23 @@ + + + + Exe + net10.0 + enable + enable + gt + + + + + + + + + + + + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs new file mode 100644 index 0000000..afc4e0a --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs @@ -0,0 +1,73 @@ +using CreativeCoders.Cli.Hosting; +using CreativeCoders.Cli.Hosting.Help; +using CreativeCoders.Core.IO; +using CreativeCoders.Core.SysEnvironment; +using CreativeCoders.GitTool.Base; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.GitTool.Base.Output; +using CreativeCoders.GitTool.Cli.Commands.Tool; +using CreativeCoders.GitTool.GitHub; +using CreativeCoders.GitTool.GitLab; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.App; + +internal static class Program +{ + internal static async Task Main(string[] args) + { + var result = await CliHostBuilder.Create() + .ConfigureServices(ConfigureServices) + .EnableHelp(HelpCommandKind.CommandOrArgument) + .ScanAssemblies(typeof(ShowConfigCommand).Assembly) + .Build() + .RunAsync(args).ConfigureAwait(false); + + return result.ExitCode; + } + + private static void ConfigureServices(IServiceCollection services) + { + var configuration = AddConfiguration(services); + + services.AddOptions(); + + services.Configure(configuration.GetSection("tool")); + + //services.AddGitFeatureCommands(); + + //services.AddGitSharedCommands(); + + services.AddGitTools(); + services.AddGitHubTools(configuration); + services.AddGitLabTools(configuration); + + services.AddSingleton(_ => AnsiConsole.Create(new AnsiConsoleSettings())); + + services.AddSingleton(); + } + + private static IConfiguration AddConfiguration(IServiceCollection services) + { + var configurationBuilder = new ConfigurationBuilder(); + + var toolConfigurationFile = FileSys.Path.Combine( + Env.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + GitToolApp.ConfigFolderName, + GitToolApp.ConfigFileName); + + if (FileSys.File.Exists(toolConfigurationFile)) + { + configurationBuilder.AddJsonFile(toolConfigurationFile); + } + + var configuration = configurationBuilder.Build(); + + services.AddSingleton(configuration); + services.AddSingleton(configuration); + + return configuration; + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj b/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj index 48c184c..e8e9bee 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj @@ -8,10 +8,10 @@ - - - - + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj index 44e8b9b..950c8fc 100644 --- a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj +++ b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj b/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj index bf52214..9c75280 100644 --- a/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj +++ b/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj @@ -5,11 +5,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -22,7 +22,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj b/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj index e650d62..b25d634 100644 --- a/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj +++ b/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj b/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj index 7f16420..2061174 100644 --- a/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj +++ b/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj b/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj index 11971b2..e642bc3 100644 --- a/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj +++ b/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From ac0fc11ccaf10bdb5406c9496acd519f21d87afb Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:34:57 +0100 Subject: [PATCH 2/7] Add branch commands: list, info, pull, and push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement `ListBranchesCommand` to list branches by location (all, local, or remote). - Implement `InfoBranchesCommand` to display details of the current branch and recent commits. - Implement `PullBranchCommand` to pull the current branch from remote. - Implement `PushBranchCommand` with options to create a remote branch if it doesn’t exist. - Add shared infrastructure and options for branch-related commands. - Update CLI projects and dependency configurations for new commands. --- .../Branches/BranchCommandGroup.cs | 10 +++ .../Branches/Info/InfoBranchesCommand.cs | 51 ++++++++++++++ .../Branches/Info/InfoBranchesOptions.cs | 11 +++ .../Branches/List/BranchLocation.cs | 8 +++ .../Branches/List/ListBranchesCommand.cs | 67 +++++++++++++++++++ .../Branches/List/ListBranchesOptions.cs | 11 +++ .../Branches/Pull/PullBranchCommand.cs | 22 ++++++ .../Branches/Pull/PullBranchOptions.cs | 10 +++ .../Branches/Push/PushBranchCommand.cs | 23 +++++++ .../Branches/Push/PushBranchOptions.cs | 18 +++++ ...CreativeCoders.GitTool.Cli.Commands.csproj | 4 +- .../Tool/ShowConfigCommand.cs | 4 +- .../CreativeCoders.GitTool.Cli.App/Program.cs | 10 ++- 13 files changed, 244 insertions(+), 5 deletions(-) create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs create mode 100644 source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs new file mode 100644 index 0000000..3334d0b --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["branch"], "Commands for branches")] + +namespace CreativeCoders.GitTool.Cli.Commands.Branches; + +public static class BranchCommandGroup +{ + public const string Name = "branch"; +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs new file mode 100644 index 0000000..5e16c27 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs @@ -0,0 +1,51 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Commands.Shared; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Info; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "info"], Description = "Shows information about the current branch")] +public class InfoBranchesCommand(IAnsiConsole ansiConsole, IGitRepository gitRepository) + : ICliCommand +{ + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + public Task ExecuteAsync(InfoBranchesOptions options) + { + _ansiConsole.WriteLine("Branch info"); + _ansiConsole.WriteLine(); + + var table = new Table() + .Border(TableBorder.None) + .HideHeaders() + .AddColumn("Name") + .AddColumn("Value") + .AddRow("Current branch:", gitRepository.Head.Name.Canonical) + .AddRow("Last Commit:", gitRepository.Head.Tip?.Sha ?? string.Empty); + + if (gitRepository.Head.TrackedBranch != null) + { + table.AddRow("Last tracked commit:", gitRepository.Head.TrackedBranch?.Tip?.Sha ?? string.Empty); + } + + _ansiConsole.Write(table); + + _ansiConsole.WriteLine(); + _ansiConsole.WriteLine("Last commits"); + + var commits = gitRepository.Head.Commits?.Take(options.CommitLogCount); + + if (commits != null) + { + _ansiConsole.PrintCommitLog(commits); + } + + _ansiConsole.WriteLine(); + + return Task.FromResult(CommandResult.Success); + } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs new file mode 100644 index 0000000..7e0914f --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs @@ -0,0 +1,11 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Info; + +[PublicAPI] +public class InfoBranchesOptions +{ + [OptionParameter('c', "commits", HelpText = "Max commit log entries listed", DefaultValue = 10)] + public int CommitLogCount { get; set; } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs new file mode 100644 index 0000000..24b359c --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs @@ -0,0 +1,8 @@ +namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; + +public enum BranchLocation +{ + All, + Local, + Remote +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs new file mode 100644 index 0000000..cabb817 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs @@ -0,0 +1,67 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Core.Collections; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.Git.Abstractions.Branches; +using CreativeCoders.SysConsole.Core.Abstractions; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "list"], Description = "Lists all branches")] +public class ListBranchesCommand(ISysConsole sysConsole, IGitRepository gitRepository) + : ICliCommand +{ + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + + private void PrintBranch(IGitBranch branch, int column0Width, int column1Width) + { + var isHead = branch.Equals(gitRepository.Head); + + _sysConsole.Write(isHead ? " * " : " "); + + _sysConsole.ForegroundColor = isHead ? ConsoleColor.Green : ConsoleColor.Yellow; + + _sysConsole + .Write(branch.Name.Friendly.PadRight(column0Width)) + .ResetColor(); + + _sysConsole.Write($" ({branch.Name.Canonical.PadRight(column1Width)}) -> "); + + _sysConsole.ForegroundColor = ConsoleColor.DarkMagenta; + + _sysConsole + .WriteLine(branch.TrackedBranch?.Name.Canonical) + .ResetColor(); + } + + public Task ExecuteAsync(ListBranchesOptions options) + { + _sysConsole + .WriteLine() + .WriteLine("List all branches:") + .WriteLine(); + + var branches = gitRepository + .Branches + .Where(x => + options.Location == BranchLocation.All + || (options.Location == BranchLocation.Local && !x.IsRemote) + || (options.Location == BranchLocation.Remote && x.IsRemote)) + .ToArray(); + + var column0Width = branches.Select(x => x.Name.Friendly.Length).Max(); + var column1Width = branches.Select(x => x.Name.Canonical.Length).Max(); + + _sysConsole.WriteLine( + $" {"Friendly".PadRight(column0Width)} {"Canonical".PadRight(column1Width)} Tracked remote branch"); + + // ReSharper disable once AccessToDisposedClosure + branches.ForEach(branch => PrintBranch(branch, column0Width, column1Width)); + + _sysConsole.WriteLine(); + + return Task.FromResult(CommandResult.Success); + } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs new file mode 100644 index 0000000..b457c0a --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs @@ -0,0 +1,11 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; + +[PublicAPI] +public class ListBranchesOptions +{ + [OptionParameter('l', "Location", HelpText = "Location of branches (all, local, remote)")] + public BranchLocation Location { get; set; } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs new file mode 100644 index 0000000..7e565c7 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Commands.Shared; +using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Pull; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] +public class PullBranchCommand(IGitToolPullCommand pullCommand, IGitRepository gitRepository) + : ICliCommand +{ + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); + + public async Task ExecuteAsync(PullBranchOptions options) + { + return await _pullCommand.ExecuteAsync(gitRepository, options.Verbose).ConfigureAwait(false); + } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs new file mode 100644 index 0000000..fdeb39d --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs @@ -0,0 +1,10 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Pull; + +[PublicAPI] +public class PullBranchOptions +{ + [OptionParameter('v', "verbose")] public bool Verbose { get; set; } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs new file mode 100644 index 0000000..a10b6f3 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs @@ -0,0 +1,23 @@ +using System.Threading.Tasks; +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Commands.Shared; +using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; + +[UsedImplicitly] +public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository gitRepository) + : ICliCommand +{ + private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); + + public async Task ExecuteAsync(PushBranchOptions options) + { + return await _pushCommand + .ExecuteAsync(gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) + .ConfigureAwait(false); + } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs new file mode 100644 index 0000000..3383731 --- /dev/null +++ b/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs @@ -0,0 +1,18 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; + +[PublicAPI] +public class PushBranchOptions +{ + private const string CreateRemoteLongName = "createremote"; + + [OptionParameter('b', CreateRemoteLongName, HelpText = "Creates a new remote branch if not tracking branch exits")] + public bool CreateRemoteBranchIfNotExists { get; set; } + + [OptionParameter('c', "confirm", HelpText = "Confirm push if remote branch exists and there are commits to push")] + public bool ConfirmPush { get; set; } + + [OptionParameter('v', "verbose")] public bool Verbose { get; set; } +} diff --git a/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj index baddc3d..99b76df 100644 --- a/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj +++ b/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -7,18 +7,18 @@ - - + + diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs b/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs index e06f3a4..3d81437 100644 --- a/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs +++ b/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs @@ -9,7 +9,7 @@ namespace CreativeCoders.GitTool.Cli.Commands.Tool; [CliCommand(["showconfig"], Description = "Shows the current repository configuration")] public class ShowConfigCommand( - IAnsiConsole console, + IAnsiConsole ansiConsole, IRepositoryConfigurations repositoryConfigurations, IGitRepositoryFactory gitRepositoryFactory) : ICliCommand { @@ -19,7 +19,7 @@ public Task ExecuteAsync() var configuration = repositoryConfigurations.GetConfiguration(repository); - console.PrintBlock() + ansiConsole.PrintBlock() .WriteLine() .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") .WriteLine() diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs index afc4e0a..77910a8 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs @@ -2,14 +2,17 @@ using CreativeCoders.Cli.Hosting.Help; using CreativeCoders.Core.IO; using CreativeCoders.Core.SysEnvironment; +using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; using CreativeCoders.GitTool.Base.Output; using CreativeCoders.GitTool.Cli.Commands.Tool; +using CreativeCoders.GitTool.Commands.Shared; using CreativeCoders.GitTool.GitHub; using CreativeCoders.GitTool.GitLab; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Spectre.Console; namespace CreativeCoders.GitTool.Cli.App; @@ -36,9 +39,12 @@ private static void ConfigureServices(IServiceCollection services) services.Configure(configuration.GetSection("tool")); + services.TryAddSingleton(sp => + sp.GetRequiredService().OpenRepositoryFromCurrentDir()); + //services.AddGitFeatureCommands(); - //services.AddGitSharedCommands(); + services.AddGitSharedCommands(); services.AddGitTools(); services.AddGitHubTools(configuration); @@ -47,6 +53,8 @@ private static void ConfigureServices(IServiceCollection services) services.AddSingleton(_ => AnsiConsole.Create(new AnsiConsoleSettings())); services.AddSingleton(); + + services.AddSysConsole(); } private static IConfiguration AddConfiguration(IServiceCollection services) From 11dcbb8770ba5de41c4fb4e1e75935c35e762098 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:42:24 +0100 Subject: [PATCH 3/7] Refactor CLI directory and project structure - Move CLI commands to `GitTool/CreativeCoders.GitTool.Cli.Commands`. - Relocate CLI app to `GitTool/CreativeCoders.GitTool.Cli.GtApp`. - Update solution and build configurations to match new structure. --- GitTools.sln | 14 +++++++------- build/BuildContext.cs | 4 ++-- .../Branches/BranchCommandGroup.cs | 0 .../Branches/Info/InfoBranchesCommand.cs | 0 .../Branches/Info/InfoBranchesOptions.cs | 0 .../Branches/List/BranchLocation.cs | 0 .../Branches/List/ListBranchesCommand.cs | 0 .../Branches/List/ListBranchesOptions.cs | 0 .../Branches/Pull/PullBranchCommand.cs | 0 .../Branches/Pull/PullBranchOptions.cs | 0 .../Branches/Push/PushBranchCommand.cs | 1 + .../Branches/Push/PushBranchOptions.cs | 0 .../CreativeCoders.GitTool.Cli.Commands.csproj | 4 ++-- .../Tool/ShowConfigCommand.cs | 0 .../CreativeCoders.GitTool.Cli.GtApp.csproj} | 3 ++- .../Program.cs | 0 16 files changed, 14 insertions(+), 12 deletions(-) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs (89%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs (100%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj (70%) rename source/{ => GitTool}/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs (100%) rename source/GitTool/{CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj => CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj} (82%) rename source/GitTool/{CreativeCoders.GitTool.Cli.App => CreativeCoders.GitTool.Cli.GtApp}/Program.cs (100%) diff --git a/GitTools.sln b/GitTools.sln index 77bc7ac..17b46cf 100644 --- a/GitTools.sln +++ b/GitTools.sln @@ -90,9 +90,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DE982092 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cli", "Cli", "{D65676E3-6820-464B-8493-597E3E1DCD98}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.App", "source\GitTool\CreativeCoders.GitTool.Cli.App\CreativeCoders.GitTool.Cli.App.csproj", "{46156AAB-B9F6-4C99-AD0A-9F370DB87679}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.GtApp", "source\GitTool\CreativeCoders.GitTool.Cli.GtApp\CreativeCoders.GitTool.Cli.GtApp.csproj", "{46156AAB-B9F6-4C99-AD0A-9F370DB87679}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.Commands", "source\CreativeCoders.GitTool.Cli.Commands\CreativeCoders.GitTool.Cli.Commands.csproj", "{AAF48CD8-DD38-4925-B0AD-798416312825}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.Commands", "source\GitTool\CreativeCoders.GitTool.Cli.Commands\CreativeCoders.GitTool.Cli.Commands.csproj", "{80C7112B-7D72-4585-BDFA-101289319B2C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -170,10 +170,10 @@ Global {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.Build.0 = Debug|Any CPU {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.ActiveCfg = Release|Any CPU {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.Build.0 = Release|Any CPU - {AAF48CD8-DD38-4925-B0AD-798416312825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AAF48CD8-DD38-4925-B0AD-798416312825}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AAF48CD8-DD38-4925-B0AD-798416312825}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AAF48CD8-DD38-4925-B0AD-798416312825}.Release|Any CPU.Build.0 = Release|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -203,7 +203,7 @@ Global {DE982092-6508-4062-99D5-6A6EE9ECB81F} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} {D65676E3-6820-464B-8493-597E3E1DCD98} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {46156AAB-B9F6-4C99-AD0A-9F370DB87679} = {D65676E3-6820-464B-8493-597E3E1DCD98} - {AAF48CD8-DD38-4925-B0AD-798416312825} = {D65676E3-6820-464B-8493-597E3E1DCD98} + {80C7112B-7D72-4585-BDFA-101289319B2C} = {D65676E3-6820-464B-8493-597E3E1DCD98} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D38E5978-8FB3-474B-BDCB-18853E21A429} diff --git a/build/BuildContext.cs b/build/BuildContext.cs index 8cf8f29..71ebe00 100644 --- a/build/BuildContext.cs +++ b/build/BuildContext.cs @@ -35,9 +35,9 @@ public class BuildContext(ICakeContext context) public DirectoryPath PublishOutputDir => ArtifactsDir.Combine("published"); - private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli.App"; + private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli.GtApp"; - private const string CliProjectFile = "CreativeCoders.GitTool.Cli.App.csproj"; + private const string CliProjectFile = "CreativeCoders.GitTool.Cli.GtApp.csproj"; public IEnumerable PublishingItems => [ diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs similarity index 89% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs index a10b6f3..5b7ae33 100644 --- a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs @@ -9,6 +9,7 @@ namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; [UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository gitRepository) : ICliCommand { diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs diff --git a/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj similarity index 70% rename from source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj index 99b76df..37a8087 100644 --- a/source/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs similarity index 100% rename from source/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj similarity index 82% rename from source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj rename to source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj index ca68d1e..f536ad2 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.App/CreativeCoders.GitTool.Cli.App.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj @@ -6,6 +6,7 @@ enable enable gt + CreativeCoders.GitTool.Cli.App @@ -14,8 +15,8 @@ - + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs similarity index 100% rename from source/GitTool/CreativeCoders.GitTool.Cli.App/Program.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs From c85c9ca4517482119990ef1544e46942ef56f75e Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:09:56 +0100 Subject: [PATCH 4/7] Add `UpdateBranchesCommand` to update local permanent branches - Implement `UpdateBranchesCommand` to pull updates for permanent local branches (e.g., production, main, develop) from remote. - Add `UpdateBranchesOptions` to include options like `SkipFetchPrune`. - Update project configuration to include the new command. --- .../Branches/Update/UpdateBranchesCommand.cs | 97 +++++++++++++++++++ .../Branches/Update/UpdateBranchesOptions.cs | 8 ++ ...CreativeCoders.GitTool.Cli.Commands.csproj | 1 - 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs new file mode 100644 index 0000000..e7ea99d --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs @@ -0,0 +1,97 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Core.Collections; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.Git.Abstractions.Branches; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.GitTool.Base.Output; +using CreativeCoders.GitTool.Commands.Shared; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Update; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "update"], + Description = "Update all permanent local branches by pulling from remote branches")] +public class UpdateBranchesCommand( + IRepositoryConfigurations repositoryConfigurations, + IGitToolPullCommand pullCommand, + IAnsiConsole ansiConsole, + ICml cml, + IGitRepository gitRepository) + : ICliCommand +{ + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); + + private readonly ICml _cml = Ensure.NotNull(cml); + + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); + + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + + public async Task ExecuteAsync(UpdateBranchesOptions options) + { + Ensure.NotNull(options); + + _ansiConsole + .EmptyLine() + .WriteMarkupLine(_cml.Caption("Update permanent local branches")) + .EmptyLine(); + + var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + + var currentBranch = gitRepository.Head; + + var updateBranchNames = new List + { + "production", + GitBranchNames.Local.GetFriendlyName(gitRepository.Info.MainBranch) + }; + + if (configuration.HasDevelopBranch) + { + updateBranchNames.Add(configuration.DevelopBranch); + } + + if (!options.SkipFetchPrune) + { + _ansiConsole.WriteLine("Fetch prune to remove remote branch refs if already deleted"); + + gitRepository.FetchPruneFromOrigin(); + } + + await UpdateBranchesAsync(gitRepository, updateBranchNames).ConfigureAwait(false); + + if (!gitRepository.Head.Equals(currentBranch)) + { + _ansiConsole.WriteMarkupLine( + $"Switch back to working branch {_cml.HighLight($"'{currentBranch.Name.Friendly}'")}"); + + gitRepository.Branches.CheckOut(currentBranch.Name.Friendly); + } + + _ansiConsole.EmptyLine(); + + return CommandResult.Success; + } + + private async Task UpdateBranchesAsync(IGitRepository repository, IEnumerable updateBranchNames) + { + await updateBranchNames + .ForEachAsync(async branchName => + { + if (repository.Branches[branchName] == null) + { + return; + } + + _ansiConsole.WriteMarkupLine($"Update local branch {_cml.HighLight($"'{branchName}'")}"); + + repository.Branches.CheckOut(branchName); + + await _pullCommand.ExecuteAsync(repository).ConfigureAwait(false); + }) + .ConfigureAwait(false); + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs new file mode 100644 index 0000000..5a3e5de --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs @@ -0,0 +1,8 @@ +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.Branches.Update; + +public class UpdateBranchesOptions +{ + [UsedImplicitly] public bool SkipFetchPrune { get; set; } +} 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 37a8087..ea73291 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,7 +7,6 @@ - From 18a6bab1d425eb6de8c3070259468cc0faaf8b72 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:41:30 +0100 Subject: [PATCH 5/7] Remove GitTool CLI commands and related implementations - Delete all CLI command classes, options, and implementations for branches, features, and releases. - Remove shared infrastructure (e.g., `GitToolCommandExecutor`, `GitToolPullCommand`, `GitToolPushCommand`, and `AnsiConsoleExtensions`). - Delete project files and references for `CreativeCoders.GitTool.Commands.*`. - Update solution and build configurations to reflect the removal. --- GitTools.sln | 45 --------- .../BranchesController.cs | 50 ---------- .../Commands/Info/InfoBranchesCommand.cs | 56 ----------- .../Commands/Info/InfoBranchesOptions.cs | 11 --- .../Commands/List/BranchLocation.cs | 8 -- .../Commands/List/ListBranchesCommand.cs | 73 -------------- .../Commands/List/ListBranchesOptions.cs | 11 --- .../Commands/Pull/PullBranchCommand.cs | 24 ----- .../Commands/Pull/PullBranchOptions.cs | 11 --- .../Commands/Push/PushBranchCommand.cs | 26 ----- .../Commands/Push/PushBranchOptions.cs | 19 ---- .../Commands/Update/UpdateBranchesCommand.cs | 99 ------------------- .../Commands/Update/UpdateBranchesOptions.cs | 8 -- ...iveCoders.GitTool.Commands.Branches.csproj | 26 ----- .../FinishFeature/FinishFeatureCommand.cs | 54 ---------- .../Commands/StartFeature/StartFeatureData.cs | 19 ---- ...iveCoders.GitTool.Commands.Features.csproj | 19 ---- .../FeaturesController.cs | 31 ------ .../Commands/Create/CreateReleaseCommand.cs | 74 -------------- .../Commands/Create/CreateReleaseOptions.cs | 16 --- ...iveCoders.GitTool.Commands.Releases.csproj | 17 ---- .../ReleasesController.cs | 25 ----- .../GitToolCommandExecutor.cs | 75 -------------- .../CommandExecuting/IGitToolCommand.cs | 8 -- .../IGitToolCommandExecutor.cs | 10 -- .../IGitToolCommandWithOptions.cs | 8 -- ...ativeCoders.GitTool.Commands.Shared.csproj | 17 ---- ...reativeCoders.GitTool.Commands.Tool.csproj | 15 --- .../ToolController.cs | 98 ------------------ ...ommandGroup.cs => BranchesCommandGroup.cs} | 2 +- .../Branches/Info/InfoBranchesCommand.cs | 4 +- .../Branches/List/ListBranchesCommand.cs | 2 +- .../Branches/Pull/PullBranchCommand.cs | 8 +- .../Branches/Push/PushBranchCommand.cs | 8 +- .../Branches/Update/UpdateBranchesCommand.cs | 4 +- ...CreativeCoders.GitTool.Cli.Commands.csproj | 6 -- .../Features/FeaturesCommandGroup.cs | 10 ++ .../Finish/FeatureFinishFailedException.cs | 11 +++ .../Features/Finish/FinishFeatureCommand.cs | 61 ++++++++++++ .../Features/Finish}/FinishFeatureData.cs | 4 +- .../Features/Finish}/FinishFeatureOptions.cs | 5 +- .../Features/Finish}/FinishFeatureSteps.cs | 51 +++++----- .../Features/Finish}/IFinishFeatureSteps.cs | 6 +- .../Features}/ServiceCollectionExtensions.cs | 4 +- .../Features/Start}/StartFeatureCommand.cs | 64 ++++++------ .../Features/Start/StartFeatureData.cs | 10 ++ .../Features/Start}/StartFeatureOptions.cs | 5 +- .../Shared}/AnsiConsoleExtensions.cs | 2 +- .../Shared}/GitToolPullCommand.cs | 8 +- .../Shared}/GitToolPushCommand.cs | 12 +-- .../Shared}/IGitToolPullCommand.cs | 2 +- .../Shared}/IGitToolPushCommand.cs | 2 +- .../Shared}/ServiceCollectionExtensions.cs | 7 +- .../Program.cs | 8 +- .../CreativeCoders.GitTool.Cli.csproj | 27 ----- .../GitToolsExceptionMiddleware.cs | 52 ---------- .../CreativeCoders.GitTool.Cli/Program.cs | 37 ------- .../CreativeCoders.GitTool.Cli/Startup.cs | 53 ---------- 58 files changed, 185 insertions(+), 1243 deletions(-) delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj delete mode 100644 source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/{BranchCommandGroup.cs => BranchesCommandGroup.cs} (82%) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature => CreativeCoders.GitTool.Cli.Commands/Features/Finish}/FinishFeatureData.cs (90%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature => CreativeCoders.GitTool.Cli.Commands/Features/Finish}/FinishFeatureOptions.cs (67%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature => CreativeCoders.GitTool.Cli.Commands/Features/Finish}/FinishFeatureSteps.cs (71%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature => CreativeCoders.GitTool.Cli.Commands/Features/Finish}/IFinishFeatureSteps.cs (69%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features => CreativeCoders.GitTool.Cli.Commands/Features}/ServiceCollectionExtensions.cs (72%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature => CreativeCoders.GitTool.Cli.Commands/Features/Start}/StartFeatureCommand.cs (59%) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature => CreativeCoders.GitTool.Cli.Commands/Features/Start}/StartFeatureOptions.cs (63%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/AnsiConsoleExtensions.cs (96%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/GitToolPullCommand.cs (92%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/GitToolPushCommand.cs (91%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/IGitToolPullCommand.cs (80%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/IGitToolPushCommand.cs (85%) rename source/GitTool/{Commands/CreativeCoders.GitTool.Commands.Shared => CreativeCoders.GitTool.Cli.Commands/Shared}/ServiceCollectionExtensions.cs (58%) delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli/Program.cs delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs diff --git a/GitTools.sln b/GitTools.sln index 17b46cf..d6b018b 100644 --- a/GitTools.sln +++ b/GitTools.sln @@ -20,8 +20,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{35D676 Directory.Build.props = source\Directory.Build.props EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Commands", "Commands", "{4AD18751-E2F6-40F3-99F6-69FA2320CA30}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Abstractions", "source\Git\CreativeCoders.Git.Abstractions\CreativeCoders.Git.Abstractions.csproj", "{AD6C98CD-A96D-4795-B9A7-F321D6597C11}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Auth.CredentialManagerCore", "source\Git\CreativeCoders.Git.Auth.CredentialManagerCore\CreativeCoders.Git.Auth.CredentialManagerCore.csproj", "{0858E655-2326-48F6-85FA-01E068A0331F}" @@ -34,12 +32,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitH EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitLab", "source\GitTool\CreativeCoders.GitTool.GitLab\CreativeCoders.GitTool.GitLab.csproj", "{F79BE247-8C60-4A51-B538-B2387C2D357F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Branches", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Branches\CreativeCoders.GitTool.Commands.Branches.csproj", "{1589F267-9A07-470B-A13C-9FE1CE5016B5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Features", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Features\CreativeCoders.GitTool.Commands.Features.csproj", "{0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Cli", "source\GitTool\CreativeCoders.GitTool.Cli\CreativeCoders.GitTool.Cli.csproj", "{35C347B1-6DA0-4D9F-8259-928C561EEF8C}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests", "tests\CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests\CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj", "{0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.UnitTests", "tests\CreativeCoders.Git.UnitTests\CreativeCoders.Git.UnitTests.csproj", "{8E5F6024-5850-4272-9A9D-45CF566C526A}" @@ -48,14 +40,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitH EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitLab.UnitTests", "tests\CreativeCoders.GitTool.GitLab.UnitTests\CreativeCoders.GitTool.GitLab.UnitTests.csproj", "{40CB3BB2-1AD4-4008-8D61-C179342F07F2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Releases", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Releases\CreativeCoders.GitTool.Commands.Releases.csproj", "{9F00E2AF-FA50-49DD-B6B0-3330E2883044}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Tool", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Tool\CreativeCoders.GitTool.Commands.Tool.csproj", "{E0E53B66-17F8-4A01-A799-8998FD0A20ED}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E4F28808-C129-4AE9-8454-08EAB02D7E7F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Commands.Shared", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Shared\CreativeCoders.GitTool.Commands.Shared.csproj", "{FC8C53FC-85DB-4A43-9D80-CEFF9047250E}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "__global", "__global", "{957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9}" ProjectSection(SolutionItems) = preProject .gitattributes = .gitattributes @@ -124,18 +110,6 @@ Global {F79BE247-8C60-4A51-B538-B2387C2D357F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F79BE247-8C60-4A51-B538-B2387C2D357F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F79BE247-8C60-4A51-B538-B2387C2D357F}.Release|Any CPU.Build.0 = Release|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Release|Any CPU.Build.0 = Release|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Release|Any CPU.Build.0 = Release|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Release|Any CPU.Build.0 = Release|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -152,18 +126,6 @@ Global {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Debug|Any CPU.Build.0 = Debug|Any CPU {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Release|Any CPU.ActiveCfg = Release|Any CPU {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Release|Any CPU.Build.0 = Release|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Release|Any CPU.Build.0 = Release|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Release|Any CPU.Build.0 = Release|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Release|Any CPU.Build.0 = Release|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -181,23 +143,16 @@ Global GlobalSection(NestedProjects) = preSolution {90C87656-57A8-4AE9-8619-DA08AA137D6A} = {35D676C5-4FB7-41AB-A60B-DD8F30ACFB5B} {EA56F26E-54C0-4C1C-986C-2785829AE2D8} = {35D676C5-4FB7-41AB-A60B-DD8F30ACFB5B} - {4AD18751-E2F6-40F3-99F6-69FA2320CA30} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {AD6C98CD-A96D-4795-B9A7-F321D6597C11} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {0858E655-2326-48F6-85FA-01E068A0331F} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {25BCE0B9-068F-4EC0-BCD0-680B3FE47626} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {CF40538D-E176-4449-B27F-22BB43E5BFD6} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {8B3F3455-5D00-47A3-B40E-F3E3E3C5E5DA} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {F79BE247-8C60-4A51-B538-B2387C2D357F} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} - {1589F267-9A07-470B-A13C-9FE1CE5016B5} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {35C347B1-6DA0-4D9F-8259-928C561EEF8C} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223} = {B7558045-D005-49D4-9205-55A32B6C99DE} {8E5F6024-5850-4272-9A9D-45CF566C526A} = {B7558045-D005-49D4-9205-55A32B6C99DE} {B6FE210C-94B0-4D65-A881-42FA3F3A9856} = {B7558045-D005-49D4-9205-55A32B6C99DE} {40CB3BB2-1AD4-4008-8D61-C179342F07F2} = {B7558045-D005-49D4-9205-55A32B6C99DE} - {9F00E2AF-FA50-49DD-B6B0-3330E2883044} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {E0E53B66-17F8-4A01-A799-8998FD0A20ED} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} {06510226-737C-4300-92A5-3FE3C5E4D6A4} = {E4F28808-C129-4AE9-8454-08EAB02D7E7F} {E91F4387-0278-43C4-AE97-E9C54E414C41} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} {DE982092-6508-4062-99D5-6A6EE9ECB81F} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs deleted file mode 100644 index 8b2101b..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Branches.Commands.Info; -using CreativeCoders.GitTool.Commands.Branches.Commands.List; -using CreativeCoders.GitTool.Commands.Branches.Commands.Pull; -using CreativeCoders.GitTool.Commands.Branches.Commands.Push; -using CreativeCoders.GitTool.Commands.Branches.Commands.Update; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches; - -[CliController("branch")] -public class BranchesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public BranchesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [UsedImplicitly] - [CliAction] - [CliAction("list", HelpText = "List repository branches")] - public async Task ListAsync(ListBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("update", HelpText = "Update all permanent local branches by pulling from remote branches")] - public async Task UpdateAsync(UpdateBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("info", HelpText = "Show infos of current branch")] - public async Task InfoAsync(InfoBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("pull", HelpText = "Pulls updates for current branch from remote")] - public async Task PullAsync(PullBranchOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("push", HelpText = "Pushes updates from current branch to remote")] - public async Task PushAsync(PushBranchOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs deleted file mode 100644 index d093c66..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Info; - -[UsedImplicitly] -public class InfoBranchesCommand : IGitToolCommandWithOptions -{ - private readonly IAnsiConsole _ansiConsole; - - public InfoBranchesCommand(IAnsiConsole ansiConsole) - { - _ansiConsole = Ensure.NotNull(ansiConsole); - } - - public Task ExecuteAsync(IGitRepository gitRepository, InfoBranchesOptions options) - { - _ansiConsole.WriteLine("Branch info"); - _ansiConsole.WriteLine(); - - var table = new Table() - .Border(TableBorder.None) - .HideHeaders() - .AddColumn("Name") - .AddColumn("Value") - .AddRow("Current branch:", gitRepository.Head.Name.Canonical) - .AddRow("Last Commit:", gitRepository.Head.Tip?.Sha ?? string.Empty); - - if (gitRepository.Head.TrackedBranch != null) - { - table.AddRow("Last tracked commit:", gitRepository.Head.TrackedBranch?.Tip?.Sha ?? string.Empty); - } - - _ansiConsole.Write(table); - - _ansiConsole.WriteLine(); - _ansiConsole.WriteLine("Last commits"); - - var commits = gitRepository.Head.Commits?.Take(options.CommitLogCount); - - if (commits != null) - { - _ansiConsole.PrintCommitLog(commits); - } - - _ansiConsole.WriteLine(); - - return Task.FromResult(0); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs deleted file mode 100644 index 6d30424..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Info; - -[PublicAPI] -public class InfoBranchesOptions -{ - [OptionParameter('c', "commits", HelpText = "Max commit log entries listed", DefaultValue = 10)] - public int CommitLogCount { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs deleted file mode 100644 index b69831b..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; - -public enum BranchLocation -{ - All, - Local, - Remote -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs deleted file mode 100644 index d34b3b2..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.Git.Abstractions.Branches; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Core.Abstractions; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; - -[UsedImplicitly] -public class ListBranchesCommand : IGitToolCommandWithOptions -{ - private readonly ISysConsole _sysConsole; - - public ListBranchesCommand(ISysConsole sysConsole) - { - _sysConsole = Ensure.NotNull(sysConsole); - } - - private void PrintBranch(IGitRepository gitRepository, IGitBranch branch, int column0Width, int column1Width) - { - var isHead = branch.Equals(gitRepository.Head); - - _sysConsole.Write(isHead ? " * " : " "); - - _sysConsole.ForegroundColor = isHead ? ConsoleColor.Green : ConsoleColor.Yellow; - - _sysConsole - .Write(branch.Name.Friendly.PadRight(column0Width)) - .ResetColor(); - - _sysConsole.Write($" ({branch.Name.Canonical.PadRight(column1Width)}) -> "); - - _sysConsole.ForegroundColor = ConsoleColor.DarkMagenta; - - _sysConsole - .WriteLine(branch.TrackedBranch?.Name.Canonical) - .ResetColor(); - } - - public Task ExecuteAsync(IGitRepository gitRepository, ListBranchesOptions options) - { - _sysConsole - .WriteLine() - .WriteLine("List all branches:") - .WriteLine(); - - var branches = gitRepository - .Branches - .Where(x => - options.Location == BranchLocation.All - || (options.Location == BranchLocation.Local && !x.IsRemote) - || (options.Location == BranchLocation.Remote && x.IsRemote)) - .ToArray(); - - var column0Width = branches.Select(x => x.Name.Friendly.Length).Max(); - var column1Width = branches.Select(x => x.Name.Canonical.Length).Max(); - - _sysConsole.WriteLine( - $" {"Friendly".PadRight(column0Width)} {"Canonical".PadRight(column1Width)} Tracked remote branch"); - - // ReSharper disable once AccessToDisposedClosure - branches.ForEach(branch => PrintBranch(gitRepository, branch, column0Width, column1Width)); - - _sysConsole.WriteLine(); - - return Task.FromResult(0); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs deleted file mode 100644 index 98f0a4f..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; - -[PublicAPI] -public class ListBranchesOptions -{ - [OptionParameter('l', "Location", HelpText = "Location of branches (all, local, remote)")] - public BranchLocation Location { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs deleted file mode 100644 index b4c51ae..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Pull; - -[UsedImplicitly] -public class PullBranchCommand : IGitToolCommandWithOptions -{ - private readonly IGitToolPullCommand _pullCommand; - - public PullBranchCommand(IGitToolPullCommand pullCommand) - { - _pullCommand = Ensure.NotNull(pullCommand); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, PullBranchOptions options) - { - return await _pullCommand.ExecuteAsync(gitRepository, options.Verbose).ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs deleted file mode 100644 index 05a0402..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Pull; - -[PublicAPI] -public class PullBranchOptions -{ - [OptionParameter('v', "verbose")] - public bool Verbose { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs deleted file mode 100644 index 0f4afaf..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Push; - -[UsedImplicitly] -public class PushBranchCommand : IGitToolCommandWithOptions -{ - private readonly IGitToolPushCommand _pushCommand; - - public PushBranchCommand(IGitToolPushCommand pushCommand) - { - _pushCommand = Ensure.NotNull(pushCommand); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, PushBranchOptions options) - { - return await _pushCommand - .ExecuteAsync(gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) - .ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs deleted file mode 100644 index b131692..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Push; - -[PublicAPI] -public class PushBranchOptions -{ - private const string CreateRemoteLongName = "createremote"; - - [OptionParameter('b', CreateRemoteLongName, HelpText = "Creates a new remote branch if not tracking branch exits")] - public bool CreateRemoteBranchIfNotExists { get; set; } - - [OptionParameter('c', "confirm", HelpText = "Confirm push if remote branch exists and there are commits to push")] - public bool ConfirmPush { get; set; } - - [OptionParameter('v', "verbose")] - public bool Verbose { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs deleted file mode 100644 index c09b1e8..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.Git.Abstractions.Branches; -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Update; - -[UsedImplicitly] -public class UpdateBranchesCommand : IGitToolCommandWithOptions -{ - private readonly IAnsiConsole _ansiConsole; - private readonly ICml _cml; - - private readonly IGitToolPullCommand _pullCommand; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - public UpdateBranchesCommand(IRepositoryConfigurations repositoryConfigurations, IGitToolPullCommand pullCommand, - IAnsiConsole ansiConsole, ICml cml) - { - _cml = Ensure.NotNull(cml); - _ansiConsole = Ensure.NotNull(ansiConsole); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _pullCommand = Ensure.NotNull(pullCommand); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, UpdateBranchesOptions options) - { - Ensure.NotNull(options); - - _ansiConsole - .EmptyLine() - .WriteMarkupLine(_cml.Caption("Update permanent local branches")) - .EmptyLine(); - - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - var currentBranch = gitRepository.Head; - - var updateBranchNames = new List - { - "production", - GitBranchNames.Local.GetFriendlyName(gitRepository.Info.MainBranch) - }; - - if (configuration.HasDevelopBranch) - { - updateBranchNames.Add(configuration.DevelopBranch); - } - - if (!options.SkipFetchPrune) - { - _ansiConsole.WriteLine("Fetch prune to remove remote branch refs if already deleted"); - - gitRepository.FetchPruneFromOrigin(); - } - - await UpdateBranchesAsync(gitRepository, updateBranchNames).ConfigureAwait(false); - - if (!gitRepository.Head.Equals(currentBranch)) - { - _ansiConsole.WriteMarkupLine( - $"Switch back to working branch {_cml.HighLight($"'{currentBranch.Name.Friendly}'")}"); - - gitRepository.Branches.CheckOut(currentBranch.Name.Friendly); - } - - _ansiConsole.EmptyLine(); - - return 0; - } - - private async Task UpdateBranchesAsync(IGitRepository repository, IEnumerable updateBranchNames) - { - await updateBranchNames - .ForEachAsync(async branchName => - { - if (repository.Branches[branchName] == null) - { - return; - } - - _ansiConsole.WriteMarkupLine($"Update local branch {_cml.HighLight($"'{branchName}'")}"); - - repository.Branches.CheckOut(branchName); - - await _pullCommand.ExecuteAsync(repository).ConfigureAwait(false); - }) - .ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs deleted file mode 100644 index 7a21237..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Update; - -public class UpdateBranchesOptions -{ - [UsedImplicitly] public bool SkipFetchPrune { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj deleted file mode 100644 index 269047e..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - enable - - - - - - - - - - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs deleted file mode 100644 index 8ae55cd..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; - -[UsedImplicitly] -public class FinishFeatureCommand : IGitToolCommandWithOptions -{ - private readonly IFinishFeatureSteps _finishFeatureSteps; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - public FinishFeatureCommand(IRepositoryConfigurations repositoryConfigurations, - IFinishFeatureSteps finishFeatureSteps) - { - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _finishFeatureSteps = Ensure.NotNull(finishFeatureSteps); - } - - private FinishFeatureData CreateData(IGitRepository gitRepository, FinishFeatureOptions options) - { - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - return new FinishFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), - configuration.GetDefaultBranchName(gitRepository.Info.MainBranch), configuration.GitServiceProviderName, - options.PullRequestTitle); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, FinishFeatureOptions options) - { - var data = CreateData(gitRepository, options); - - _finishFeatureSteps.UpdateFeatureBranch(data); - - _finishFeatureSteps.MergeDefaultBranch(data); - - await _finishFeatureSteps.PushFeatureBranch(data).ConfigureAwait(false); - - // Ensure remote branch creation and use it for pull request - - await _finishFeatureSteps.CreatePullRequest(data).ConfigureAwait(false); - - gitRepository.Branches.CheckOut(data.DefaultBranch); - - gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); - - return ReturnCodes.Success; - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs deleted file mode 100644 index 1aa11e6..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs +++ /dev/null @@ -1,19 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; - -public class StartFeatureData -{ - public StartFeatureData(IGitRepository gitRepository, string featureBranch, string defaultBranch) - { - GitRepository = gitRepository; - FeatureBranch = featureBranch; - DefaultBranch = defaultBranch; - } - - public IGitRepository GitRepository { get; } - - public string FeatureBranch { get; } - - public string DefaultBranch { get; } -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj deleted file mode 100644 index 9e87b32..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - enable - - - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs deleted file mode 100644 index dd475b1..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; -using CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Features; - -[CliController("feature")] -public class FeaturesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public FeaturesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [UsedImplicitly] - [CliAction("start", HelpText = "Start a new feature")] - public async Task StartAsync(StartFeatureOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("finish", HelpText = "Finish an active feature")] - public async Task FinishAsync(FinishFeatureOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs deleted file mode 100644 index 2fca885..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.Git.Abstractions.Branches; -using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Core.Abstractions; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Releases.Commands.Create; - -[UsedImplicitly] -public class CreateReleaseCommand : IGitToolCommandWithOptions -{ - private readonly IGitServiceProviders _gitServiceProviders; - - private readonly ISysConsole _sysConsole; - - public CreateReleaseCommand(ISysConsole sysConsole, - IGitServiceProviders gitServiceProviders) - { - _sysConsole = Ensure.NotNull(sysConsole); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - } - - private async Task MergeDevelopToMain(IGitRepository repository, string mainBranchName, - CreateReleaseOptions options) - { - var provider = await _gitServiceProviders.GetServiceProviderAsync(repository, null); - - var createPullRequest = new GitCreatePullRequest(repository.Info.RemoteUri, - $"Release {options.Version}", "develop", mainBranchName); - - _ = await provider.CreatePullRequestAsync(createPullRequest); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, CreateReleaseOptions options) - { - var mainBranchName = GitBranchNames.Local.GetCanonicalName(gitRepository.Info.MainBranch); - - if (gitRepository.Branches["develop"] != null) - { - _sysConsole.WriteLine( - $"Repository has a develop branch. So first a merge from develop -> {mainBranchName} must be done."); - - await MergeDevelopToMain(gitRepository, mainBranchName, options); - } - - var tagName = $"v{options.Version}"; - - _sysConsole.WriteLine($"Create tag '{tagName}'"); - - gitRepository.Branches.CheckOut(mainBranchName); - - gitRepository.Pull(); - - var versionTag = gitRepository.Tags.CreateTagWithMessage(tagName, mainBranchName, $"Version {options.Version}"); - - if (options.PushAllTags) - { - _sysConsole.WriteLine("Push all tags to remote"); - - gitRepository.Tags.PushAllTags(); - } - else - { - _sysConsole.WriteLine($"Push tag '{versionTag.Name.Canonical}'"); - - gitRepository.Tags.PushTag(versionTag); - } - - return 0; - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs deleted file mode 100644 index 78468b3..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Releases.Commands.Create; - -[PublicAPI] -public class CreateReleaseOptions -{ - private const string PushAllTagsLongName = "alltags"; - - [OptionValue(0, IsRequired = true)] - public string? Version { get; set; } - - [OptionParameter('a', PushAllTagsLongName)] - public bool PushAllTags { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj deleted file mode 100644 index f1f25a3..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - enable - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs deleted file mode 100644 index e8b230c..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Releases.Commands.Create; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Releases; - -[PublicAPI] -[CliController("release")] -public class ReleasesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public ReleasesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [CliAction("create")] - public async Task CreateAsync(CreateReleaseOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs deleted file mode 100644 index 0414400..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs +++ /dev/null @@ -1,75 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.Core.Reflection; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base.Configurations; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public class GitToolCommandExecutor : IGitToolCommandExecutor -{ - private readonly IGitRepositoryFactory _gitRepositoryFactory; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - private readonly IServiceProvider _serviceProvider; - - public GitToolCommandExecutor(IServiceProvider serviceProvider, IGitRepositoryFactory gitRepositoryFactory, - IRepositoryConfigurations repositoryConfigurations) - { - _serviceProvider = Ensure.NotNull(serviceProvider); - _gitRepositoryFactory = Ensure.NotNull(gitRepositoryFactory); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - } - - public async Task ExecuteAsync() - where TCommand : IGitToolCommand - { - var command = typeof(TCommand).CreateInstance(_serviceProvider); - - if (command == null) - { - throw new InvalidOperationException("Command object cannot be created"); - } - - using var gitRepository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - if (configuration.DisableCertificateValidation) - { - gitRepository.CertificateCheck = (_, args) => - { - args.IsValid = true; - return true; - }; - } - - return await command.ExecuteAsync(gitRepository).ConfigureAwait(false); - } - - public async Task ExecuteAsync(TCommandOptions options) - where TCommand : IGitToolCommandWithOptions - { - var command = typeof(TCommand).CreateInstance>(_serviceProvider); - - if (command == null) - { - throw new InvalidOperationException("Command object cannot be created"); - } - - using var gitRepository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - if (configuration.DisableCertificateValidation) - { - gitRepository.CertificateCheck = (_, args) => - { - args.IsValid = true; - return true; - }; - } - - return await command.ExecuteAsync(gitRepository, options).ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs deleted file mode 100644 index cd6cbf7..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs +++ /dev/null @@ -1,8 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommand -{ - Task ExecuteAsync(IGitRepository gitRepository); -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs deleted file mode 100644 index e9898e8..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommandExecutor -{ - Task ExecuteAsync() - where TCommand : IGitToolCommand; - - Task ExecuteAsync(TCommandOptions options) - where TCommand : IGitToolCommandWithOptions; -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs deleted file mode 100644 index be9e584..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommandWithOptions -{ - Task ExecuteAsync(IGitRepository gitRepository, TOptions options); -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj deleted file mode 100644 index 57dfe28..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - enable - enable - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj deleted file mode 100644 index 6a65ae6..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - enable - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs deleted file mode 100644 index cb89694..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.SysEnvironment; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using CreativeCoders.SysConsole.Core; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Commands.Tool; - -[PublicAPI] -[CliController] -public class ToolController -{ - private readonly IAnsiConsole _console; - - private readonly IGitRepositoryFactory _gitRepositoryFactory; - - private readonly IGitServiceProviders _gitServiceProviders; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - public ToolController(IAnsiConsole console, IRepositoryConfigurations repositoryConfigurations, - IGitRepositoryFactory gitRepositoryFactory, IGitServiceProviders gitServiceProviders) - { - _console = Ensure.NotNull(console); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - _gitRepositoryFactory = Ensure.NotNull(gitRepositoryFactory); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - } - - [CliAction("setup")] - public async Task Setup() - { - using var repository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(repository); - - _console.PrintBlock() - .WriteLine() - .WriteLine("Development branch (empty = no development branch)"); - - var developBranch = - _console.Prompt(new TextPrompt($"(Current value = '{configuration.DevelopBranch}'): ") - { AllowEmpty = true }); - - configuration.DevelopBranch = developBranch ?? string.Empty; - configuration.HasDevelopBranch = !string.IsNullOrEmpty(developBranch); - - var featureBranchPrefix = _console.Prompt(new TextPrompt( - $"Prefix for feature branches (Empty = current value '{configuration.FeatureBranchPrefix}'): ") - { AllowEmpty = true }); - - if (!string.IsNullOrEmpty(featureBranchPrefix)) - { - configuration.FeatureBranchPrefix = featureBranchPrefix; - } - - var selectionPrompt = new SelectionPrompt(); - - var gitProviderName = _console.Prompt(selectionPrompt.AddChoices(_gitServiceProviders.ProviderNames)); - - if (!string.IsNullOrEmpty(gitProviderName)) - { - configuration.GitServiceProviderName = gitProviderName; - } - - var disableCertValidationPrompt = new ConfirmationPrompt("Disable certificate check (true/false): ") - { DefaultValue = configuration.DisableCertificateValidation }; - - configuration.DisableCertificateValidation = _console.Prompt(disableCertValidationPrompt); - - await _repositoryConfigurations.SaveConfigurationAsync(repository.Info.RemoteUri, configuration); - } - - // ReSharper disable once StringLiteralTypo - [CliAction("showconfig")] - public void ShowConfig() - { - using var repository = _gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); - - var configuration = _repositoryConfigurations.GetConfiguration(repository); - - _console.PrintBlock() - .WriteLine() - .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") - .WriteLine() - .WriteLine($"HasDevelopBranch: {configuration.HasDevelopBranch}") - .WriteLine($"DevelopBranch: {configuration.DevelopBranch}") - .WriteLine($"FeatureBranchPrefix: {configuration.FeatureBranchPrefix}") - .WriteLine($"GitServiceProviderName: {configuration.GitServiceProviderName}") - .WriteLine($"DisableCertificateValidation: {configuration.DisableCertificateValidation}") - .WriteLine(); - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs similarity index 82% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs index 3334d0b..6ff1fd5 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchCommandGroup.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs @@ -4,7 +4,7 @@ namespace CreativeCoders.GitTool.Cli.Commands.Branches; -public static class BranchCommandGroup +public static class BranchesCommandGroup { public const string Name = "branch"; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs index 5e16c27..063e5ef 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs @@ -1,14 +1,14 @@ using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; +using CreativeCoders.GitTool.Cli.Commands.Shared; using JetBrains.Annotations; using Spectre.Console; namespace CreativeCoders.GitTool.Cli.Commands.Branches.Info; [UsedImplicitly] -[CliCommand([BranchCommandGroup.Name, "info"], Description = "Shows information about the current branch")] +[CliCommand([BranchesCommandGroup.Name, "info"], Description = "Shows information about the current branch")] public class InfoBranchesCommand(IAnsiConsole ansiConsole, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs index cabb817..c9faefb 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs @@ -9,7 +9,7 @@ namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; [UsedImplicitly] -[CliCommand([BranchCommandGroup.Name, "list"], Description = "Lists all branches")] +[CliCommand([BranchesCommandGroup.Name, "list"], Description = "Lists all branches")] public class ListBranchesCommand(ISysConsole sysConsole, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs index 7e565c7..d18fed6 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs @@ -1,15 +1,13 @@ -using System.Threading.Tasks; -using CreativeCoders.Cli.Core; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using JetBrains.Annotations; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; namespace CreativeCoders.GitTool.Cli.Commands.Branches.Pull; [UsedImplicitly] -[CliCommand([BranchCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] +[CliCommand([BranchesCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] public class PullBranchCommand(IGitToolPullCommand pullCommand, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs index 5b7ae33..fc3d308 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs @@ -1,15 +1,13 @@ -using System.Threading.Tasks; -using CreativeCoders.Cli.Core; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using JetBrains.Annotations; +using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; [UsedImplicitly] -[CliCommand([BranchCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] +[CliCommand([BranchesCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs index e7ea99d..1108531 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs @@ -5,14 +5,14 @@ using CreativeCoders.Git.Abstractions.Branches; using CreativeCoders.GitTool.Base.Configurations; using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Commands.Shared; using JetBrains.Annotations; using Spectre.Console; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; namespace CreativeCoders.GitTool.Cli.Commands.Branches.Update; [UsedImplicitly] -[CliCommand([BranchCommandGroup.Name, "update"], +[CliCommand([BranchesCommandGroup.Name, "update"], Description = "Update all permanent local branches by pulling from remote branches")] public class UpdateBranchesCommand( IRepositoryConfigurations repositoryConfigurations, 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 ea73291..aa68630 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 @@ -6,18 +6,12 @@ enable - - - - - - diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs new file mode 100644 index 0000000..804dd32 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["feature"], "Commands for managing features")] + +namespace CreativeCoders.GitTool.Cli.Commands.Features; + +public static class FeaturesCommandGroup +{ + public const string Name = "feature"; +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs new file mode 100644 index 0000000..a9ffbb9 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs @@ -0,0 +1,11 @@ +using CreativeCoders.Cli.Hosting.Exceptions; + +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; + +public class FeatureFinishFailedException : CliExitException +{ + public FeatureFinishFailedException(string message, int exitCode, Exception? exception = null) : base(message, + exitCode, exception) + { + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs new file mode 100644 index 0000000..b979d90 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs @@ -0,0 +1,61 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base.Configurations; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; + +[UsedImplicitly] +[CliCommand([FeaturesCommandGroup.Name, "finish"], Description = "Finish a feature branch and create a pull request")] +public class FinishFeatureCommand( + IAnsiConsole ansiConsole, + IRepositoryConfigurations repositoryConfigurations, + IFinishFeatureSteps finishFeatureSteps, + IGitRepository gitRepository) + : ICliCommand +{ + private readonly IFinishFeatureSteps _finishFeatureSteps = Ensure.NotNull(finishFeatureSteps); + + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + + private FinishFeatureData CreateData(FinishFeatureOptions options) + { + var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + + return new FinishFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), + configuration.GetDefaultBranchName(gitRepository.Info.MainBranch), configuration.GitServiceProviderName, + options.PullRequestTitle); + } + + public async Task ExecuteAsync(FinishFeatureOptions options) + { + var data = CreateData(options); + + try + { + _finishFeatureSteps.UpdateFeatureBranch(data); + + _finishFeatureSteps.MergeDefaultBranch(data); + + await _finishFeatureSteps.PushFeatureBranch(data).ConfigureAwait(false); + + // Ensure remote branch creation and use it for pull request + + await _finishFeatureSteps.CreatePullRequest(data).ConfigureAwait(false); + } + catch (FeatureFinishFailedException e) + { + ansiConsole.MarkupLine($"[red]{e.Message}[/]"); + + return e.ExitCode; + } + + gitRepository.Branches.CheckOut(data.DefaultBranch); + + gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); + + return CommandResult.Success; + } +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs similarity index 90% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs index e671bd1..b705997 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; public class FinishFeatureData { @@ -23,4 +23,4 @@ public FinishFeatureData(IGitRepository repository, string featureBranch, string public string? PullRequestTitle { get; } public IGitRepository Repository { get; } -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs similarity index 67% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs index 44782fb..7093bc1 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs @@ -1,15 +1,14 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; [PublicAPI] public class FinishFeatureOptions { private const string PullRequestTitleName = "prtitle"; - [OptionValue(0, IsRequired = true)] - public string FeatureName { get; set; } = null!; + [OptionValue(0, IsRequired = true)] public string FeatureName { get; set; } = null!; [OptionParameter('t', PullRequestTitleName, HelpText = "Title for pull request that is created")] public string? PullRequestTitle { get; set; } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs similarity index 71% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs index 0cd264b..33068e3 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs @@ -1,30 +1,24 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; +using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Commits; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Exceptions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.SysConsole.App; using CreativeCoders.SysConsole.Core.Abstractions; +using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; -public class FinishFeatureSteps : IFinishFeatureSteps +public class FinishFeatureSteps( + ISysConsole sysConsole, + IGitServiceProviders gitServiceProviders, + IGitToolPushCommand pushCommand) + : IFinishFeatureSteps { - private readonly IGitServiceProviders _gitServiceProviders; + private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - private readonly ISysConsole _sysConsole; + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); - private readonly IGitToolPushCommand _pushCommand; - - public FinishFeatureSteps(ISysConsole sysConsole, IGitServiceProviders gitServiceProviders, - IGitToolPushCommand pushCommand) - { - _sysConsole = Ensure.NotNull(sysConsole, nameof(sysConsole)); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders, nameof(gitServiceProviders)); - _pushCommand = Ensure.NotNull(pushCommand, nameof(pushCommand)); - } + private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); public void UpdateFeatureBranch(FinishFeatureData data) { @@ -38,8 +32,8 @@ public void UpdateFeatureBranch(FinishFeatureData data) .WriteLineError("Feature branch has uncommitted changes. Please commit or revert and try again") .WriteLine(); - throw new ConsoleException(ReturnCodes.BranchHasUncommittedChanges, - "Feature branch has uncommitted changes"); + throw new FeatureFinishFailedException("Feature branch has uncommitted changes", + ReturnCodes.BranchHasUncommittedChanges); } _sysConsole @@ -64,8 +58,8 @@ public void UpdateFeatureBranch(FinishFeatureData data) .WriteLineError("Pull feature branch updates from remote caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge feature branch from remote into local caused merge conflicts"); + throw new FeatureFinishFailedException("Merge feature branch from remote into local caused merge conflicts", + ReturnCodes.MergeConflicts); } _sysConsole @@ -92,8 +86,8 @@ public void MergeDefaultBranch(FinishFeatureData data) .WriteLineError("Pull default branch updates from remote caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge default branch from remote into local caused merge conflicts"); + throw new FeatureFinishFailedException("Merge default branch from remote into local caused merge conflicts", + ReturnCodes.MergeConflicts); } _sysConsole @@ -108,8 +102,8 @@ public void MergeDefaultBranch(FinishFeatureData data) .WriteLineError("Merge default branch to feature branch caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge default branch to feature branch caused merge conflicts"); + throw new FeatureFinishFailedException("Merge default branch to feature branch caused merge conflicts", + ReturnCodes.MergeConflicts); } data.Repository.Branches.CheckOut(data.FeatureBranch); @@ -132,7 +126,8 @@ public async Task PushFeatureBranch(FinishFeatureData data) public async Task CreatePullRequest(FinishFeatureData data) { - var provider = await _gitServiceProviders.GetServiceProviderAsync(data.Repository, data.RepositoryGitServiceProviderName); + var provider = + await _gitServiceProviders.GetServiceProviderAsync(data.Repository, data.RepositoryGitServiceProviderName); if (await provider.PullRequestExists(data.Repository.Info.RemoteUri, data.FeatureBranch, data.DefaultBranch)) @@ -162,7 +157,7 @@ public async Task CreatePullRequest(FinishFeatureData data) .WriteLineError(e.Message.Trim()) .WriteLine(); - throw new ConsoleException(ReturnCodes.GeneralError, "Create pull request failed"); + throw new FeatureFinishFailedException("Create pull request failed", ReturnCodes.GeneralError); } } -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs similarity index 69% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs index 1126c91..b9c385e 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; public interface IFinishFeatureSteps { @@ -11,4 +9,4 @@ public interface IFinishFeatureSteps void MergeDefaultBranch(FinishFeatureData data); Task CreatePullRequest(FinishFeatureData data); -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs similarity index 72% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs index 61ff829..165dc8b 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +using CreativeCoders.GitTool.Cli.Commands.Features.Finish; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace CreativeCoders.GitTool.Commands.Features; +namespace CreativeCoders.GitTool.Cli.Commands.Features; public static class ServiceCollectionExtensions { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs similarity index 59% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs index 167c72f..332c0bb 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs @@ -1,32 +1,29 @@ -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Core.Collections; using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; [UsedImplicitly] -public class StartFeatureCommand : IGitToolCommandWithOptions +[CliCommand([FeaturesCommandGroup.Name, "start"], Description = "Start a new feature branch")] +public class StartFeatureCommand( + ISysConsole sysConsole, + IRepositoryConfigurations repositoryConfigurations, + IGitToolPullCommand pullCommand, + IGitRepository gitRepository) + : ICliCommand { - private readonly IGitToolPullCommand _pullCommand; - private readonly IRepositoryConfigurations _repositoryConfigurations; + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); - private readonly ISysConsole _sysConsole; + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - public StartFeatureCommand(ISysConsole sysConsole, - IRepositoryConfigurations repositoryConfigurations, - IGitToolPullCommand pullCommand) - { - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _sysConsole = Ensure.NotNull(sysConsole); - _pullCommand = Ensure.NotNull(pullCommand); - } + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); private void PrintStartFeatureData(StartFeatureData data) { @@ -37,7 +34,7 @@ private void PrintStartFeatureData(StartFeatureData data) private void CheckIfFeatureBranchExists(StartFeatureData data) { - var branch = data.GitRepository.Branches[data.FeatureBranch]; + var branch = gitRepository.Branches[data.FeatureBranch]; if (branch != null) { @@ -48,14 +45,14 @@ private void CheckIfFeatureBranchExists(StartFeatureData data) //data.GitRepository.Remotes[data.FeatureBranch] } - private void CreateAndCheckOutFeatureBranch(IGitRepository repository, - StartFeatureOptions options, RepositoryConfiguration repositoryConfiguration) + private void CreateAndCheckOutFeatureBranch(StartFeatureOptions options, + RepositoryConfiguration repositoryConfiguration) { var featureBranchName = repositoryConfiguration.GetFeatureBranchName(options.FeatureName); _sysConsole.WriteLine($"Creating feature branch '{featureBranchName}' ..."); - var featureBranch = repository.Branches.CreateBranch(featureBranchName); + var featureBranch = gitRepository.Branches.CreateBranch(featureBranchName); if (featureBranch == null) { @@ -69,7 +66,7 @@ private void CreateAndCheckOutFeatureBranch(IGitRepository repository, .WriteLine() .WriteLine("Checking out feature branch..."); - var checkedOutBranch = repository.Branches.CheckOut(featureBranch.Name.Canonical); + var checkedOutBranch = gitRepository.Branches.CheckOut(featureBranch.Name.Canonical); if (checkedOutBranch == null) { @@ -83,10 +80,9 @@ private void CreateAndCheckOutFeatureBranch(IGitRepository repository, .WriteLine(); } - private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, - RepositoryConfiguration repositoryConfiguration) + private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositoryConfiguration) { - var baseBranchName = repositoryConfiguration.GetDefaultBranchName(repository.Info.MainBranch); + var baseBranchName = repositoryConfiguration.GetDefaultBranchName(gitRepository.Info.MainBranch); if (string.IsNullOrEmpty(baseBranchName)) { @@ -95,7 +91,7 @@ private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, .WriteLine() .WriteLine("Existing branches:"); - repository.Branches.ForEach(branch => + gitRepository.Branches.ForEach(branch => _sysConsole.WriteLine($" {branch.Name.Friendly} -> {branch.TrackedBranch?.Name.Friendly}")); return; @@ -103,39 +99,39 @@ private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, _sysConsole.WriteLine($"Checkout base branch '{baseBranchName}'"); - repository.Branches.CheckOut(baseBranchName); + gitRepository.Branches.CheckOut(baseBranchName); _sysConsole .WriteLine("Base branch checked out") .WriteLine() .WriteLine("Pulling from origin"); - await _pullCommand.ExecuteAsync(repository).ConfigureAwait(false); + await _pullCommand.ExecuteAsync(gitRepository).ConfigureAwait(false); - repository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); + gitRepository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); } - private StartFeatureData CreateData(IGitRepository gitRepository, StartFeatureOptions options) + private StartFeatureData CreateData(StartFeatureOptions options) { var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - return new StartFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), + return new StartFeatureData(configuration.GetFeatureBranchName(options.FeatureName), configuration.GetDefaultBranchName(gitRepository.Info.MainBranch)); } - public async Task ExecuteAsync(IGitRepository gitRepository, StartFeatureOptions options) + public async Task ExecuteAsync(StartFeatureOptions options) { var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - var data = CreateData(gitRepository, options); + var data = CreateData(options); PrintStartFeatureData(data); CheckIfFeatureBranchExists(data); - await CheckOutAndUpdateBaseBranch(gitRepository, configuration).ConfigureAwait(false); + await CheckOutAndUpdateBaseBranch(configuration).ConfigureAwait(false); - CreateAndCheckOutFeatureBranch(gitRepository, options, configuration); + CreateAndCheckOutFeatureBranch(options, configuration); if (options.PushAfterCreate) { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs new file mode 100644 index 0000000..ec9e12f --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Git.Abstractions; + +namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; + +public class StartFeatureData(string featureBranch, string defaultBranch) +{ + public string FeatureBranch { get; } = featureBranch; + + public string DefaultBranch { get; } = defaultBranch; +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs similarity index 63% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs index 1907373..9dc4497 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs @@ -1,15 +1,14 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; +namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; [PublicAPI] public class StartFeatureOptions { private const string PushAfterCreateName = "pushaftercreate"; - [OptionValue(0, IsRequired = true)] - public string FeatureName { get; set; } = null!; + [OptionValue(0, IsRequired = true)] public string FeatureName { get; set; } = null!; [OptionParameter('p', PushAfterCreateName)] public bool PushAfterCreate { get; set; } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs similarity index 96% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs index 78f43a3..68e9bbb 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs @@ -3,7 +3,7 @@ using CreativeCoders.Git.Abstractions.Commits; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public static class AnsiConsoleExtensions { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs similarity index 92% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs index 965be7c..c599576 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs @@ -5,7 +5,7 @@ using CreativeCoders.GitTool.Base.Output; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public class GitToolPullCommand : IGitToolPullCommand { @@ -15,8 +15,8 @@ public class GitToolPullCommand : IGitToolPullCommand public GitToolPullCommand(IAnsiConsole ansiConsole, ICml cml) { - _ansiConsole = Ensure.NotNull(ansiConsole, nameof(ansiConsole)); - _cml = Ensure.NotNull(cml, nameof(cml)); + _ansiConsole = Ensure.NotNull(ansiConsole); + _cml = Ensure.NotNull(cml); } public Task ExecuteAsync(IGitRepository gitRepository) @@ -51,7 +51,7 @@ public Task ExecuteAsync(IGitRepository gitRepository, bool verbose) private void CheckoutProgress(string path, int completedSteps, int totalSteps) { - _ansiConsole.MarkupLine($"{_cml.HighLight(path)} {completedSteps/totalSteps}"); + _ansiConsole.MarkupLine($"{_cml.HighLight(path)} {completedSteps / totalSteps}"); } private void PrintMergeResultStatus(GitMergeStatus mergeResultStatus) diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs similarity index 91% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs index 93f06c1..ef9671f 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs @@ -6,7 +6,7 @@ using CreativeCoders.GitTool.Base.Output; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public class GitToolPushCommand : IGitToolPushCommand { @@ -16,15 +16,15 @@ public class GitToolPushCommand : IGitToolPushCommand public GitToolPushCommand(IAnsiConsole ansiConsole, ICml cml) { - _ansiConsole = Ensure.NotNull(ansiConsole, nameof(ansiConsole)); - _cml = Ensure.NotNull(cml, nameof(cml)); + _ansiConsole = Ensure.NotNull(ansiConsole); + _cml = Ensure.NotNull(cml); } public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool confirmPush) => ExecuteAsync(gitRepository, createRemoteIsNotExists, confirmPush, false); - public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool verbose, - bool confirmPush) + public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool confirmPush, + bool verbose) { _ansiConsole .WriteMarkupLine("Push updates to remote origin") @@ -60,7 +60,7 @@ private bool DoConfirm() var key = _ansiConsole.Input.ReadKey(false); - return key is {KeyChar: 'y'}; + return key is { KeyChar: 'y' }; } private void OnGitUnPushedCommits(IEnumerable commits) diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs similarity index 80% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs index c1c80a3..2646f6b 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public interface IGitToolPullCommand { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs similarity index 85% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs index 0bd6a8f..b3d6f7d 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public interface IGitToolPushCommand { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs similarity index 58% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs index abeda55..fb412aa 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs @@ -1,8 +1,7 @@ -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public static class ServiceCollectionExtensions { @@ -11,7 +10,5 @@ public static void AddGitSharedCommands(this IServiceCollection services) services.TryAddTransient(); services.TryAddTransient(); - - services.TryAddTransient(); } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs index 77910a8..09ff48d 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -6,14 +6,14 @@ using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; using CreativeCoders.GitTool.Base.Output; +using CreativeCoders.GitTool.Cli.Commands.Features; +using CreativeCoders.GitTool.Cli.Commands.Shared; using CreativeCoders.GitTool.Cli.Commands.Tool; -using CreativeCoders.GitTool.Commands.Shared; using CreativeCoders.GitTool.GitHub; using CreativeCoders.GitTool.GitLab; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using Spectre.Console; namespace CreativeCoders.GitTool.Cli.App; @@ -42,7 +42,7 @@ private static void ConfigureServices(IServiceCollection services) services.TryAddSingleton(sp => sp.GetRequiredService().OpenRepositoryFromCurrentDir()); - //services.AddGitFeatureCommands(); + services.AddGitFeatureCommands(); services.AddGitSharedCommands(); @@ -50,8 +50,6 @@ private static void ConfigureServices(IServiceCollection services) services.AddGitHubTools(configuration); services.AddGitLabTools(configuration); - services.AddSingleton(_ => AnsiConsole.Create(new AnsiConsoleSettings())); - services.AddSingleton(); services.AddSysConsole(); diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj b/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj deleted file mode 100644 index e8e9bee..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - Exe - gt - enable - win-x64;linux-x64;linux-arm - - - - - - - - - - - - - - - - - - - - diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs b/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs deleted file mode 100644 index 579d5e1..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.SysConsole.Cli.Actions.Exceptions; -using CreativeCoders.SysConsole.Cli.Actions.Runtime; -using CreativeCoders.SysConsole.Cli.Actions.Runtime.Middleware; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Cli; - -[UsedImplicitly] -public class GitToolsExceptionMiddleware : CliActionMiddlewareBase -{ - private readonly IAnsiConsole _ansiConsole; - - private readonly ICml _cml; - - public GitToolsExceptionMiddleware(Func next, - IAnsiConsole ansiConsole, ICml cml) - : base(next) - { - _cml = Ensure.NotNull(cml); - _ansiConsole = Ensure.NotNull(ansiConsole); - } - - public override async Task InvokeAsync(CliActionContext context) - { - try - { - await Next(context); - } - catch (AmbiguousRouteException e) - { - _ansiConsole.WriteMarkupLine(_cml.Error($"Unknown command '{string.Join(' ', e.Arguments)}'")); - - e.Routes.ForEach(x => _ansiConsole.WriteMarkupLine(string.Join(' ', x.RouteParts))); - } - catch (Exception e) - { - _ansiConsole - .WriteMarkupLine(_cml.Error("An error occurred:")) - .WriteLineEx(e.ToString()) - .WriteMarkupLine(e.GetBaseException().Message) - .WriteLine(); - - context.ReturnCode = -1024; - } - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs deleted file mode 100644 index b0efba5..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Threading.Tasks; -using CreativeCoders.Core.IO; -using CreativeCoders.Core.SysEnvironment; -using CreativeCoders.GitTool.Base; -using CreativeCoders.SysConsole.App; -using CreativeCoders.SysConsole.Cli.Actions; -using Microsoft.Extensions.Configuration; - -namespace CreativeCoders.GitTool.Cli; - -public static class Program -{ - public static async Task Main(string[] args) - { - return await BuildApp(args).RunAsync(); - } - - private static IConsoleApp BuildApp(string[] args) - { - return new ConsoleAppBuilder(args) - .UseActions() - .UseConfiguration(x => - { - var toolConfigurationFile = FileSys.Path.Combine( - Env.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - GitToolApp.ConfigFolderName, - GitToolApp.ConfigFileName); - - if (FileSys.File.Exists(toolConfigurationFile)) - { - x.AddJsonFile(toolConfigurationFile); - } - }) - .Build(); - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs b/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs deleted file mode 100644 index 9f70834..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs +++ /dev/null @@ -1,53 +0,0 @@ -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Commands.Branches; -using CreativeCoders.GitTool.Commands.Features; -using CreativeCoders.GitTool.Commands.Releases; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Tool; -using CreativeCoders.GitTool.GitHub; -using CreativeCoders.GitTool.GitLab; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Runtime; -using CreativeCoders.SysConsole.Cli.Actions.Runtime.Middleware; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Cli; - -public class Startup : ICliStartup -{ - public void ConfigureServices(IServiceCollection services, IConfiguration configuration) - { - services.AddOptions(); - - services.Configure(configuration.GetSection("tool")); - - services.AddGitFeatureCommands(); - - services.AddGitSharedCommands(); - - services.AddGitTools(); - services.AddGitHubTools(configuration); - services.AddGitLabTools(configuration); - - services.AddSingleton(_ => AnsiConsole.Create(new AnsiConsoleSettings())); - - services.AddSingleton(); - } - - public void Configure(ICliActionRuntimeBuilder runtimeBuilder) - { - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - - runtimeBuilder.UseMiddleware(); - - runtimeBuilder.UseHelp(); - - runtimeBuilder.UseRouting(); - } -} From 3003393eb5ab7e38bfd31a4268b3935a42a119ca Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:46:47 +0100 Subject: [PATCH 6/7] Add `CreateReleaseCommand` to manage Git release workflow - Implement `CreateReleaseCommand` to create versioned releases with tags and optional push to remote. - Add `CreateReleaseOptions` to handle version and tag-push options. - Introduce `ReleaseCommandGroup` for organizing release-related commands. - Refactor existing `Branches` and `Features` command namespaces to `BranchGroup` and `FeatureGroup`. --- .../BranchCommandGroup.cs} | 4 +- .../Info/InfoBranchesCommand.cs | 4 +- .../Info/InfoBranchesOptions.cs | 2 +- .../BranchGroup/List/BranchLocation.cs | 8 +++ .../List/ListBranchesCommand.cs | 4 +- .../List/ListBranchesOptions.cs | 2 +- .../Pull/PullBranchCommand.cs | 4 +- .../Pull/PullBranchOptions.cs | 2 +- .../Push/PushBranchCommand.cs | 4 +- .../Push/PushBranchOptions.cs | 2 +- .../Update/UpdateBranchesCommand.cs | 4 +- .../Update/UpdateBranchesOptions.cs | 2 +- .../Branches/List/BranchLocation.cs | 8 --- .../FeatureCommandGroup.cs} | 4 +- .../Finish/FeatureFinishFailedException.cs | 2 +- .../Finish/FinishFeatureCommand.cs | 4 +- .../Finish/FinishFeatureData.cs | 2 +- .../Finish/FinishFeatureOptions.cs | 2 +- .../Finish/FinishFeatureSteps.cs | 2 +- .../Finish/IFinishFeatureSteps.cs | 2 +- .../ServiceCollectionExtensions.cs | 4 +- .../Start/StartFeatureCommand.cs | 4 +- .../Start/StartFeatureData.cs | 4 +- .../Start/StartFeatureOptions.cs | 2 +- .../Create/CreateReleaseCommand.cs | 72 +++++++++++++++++++ .../Create/CreateReleaseOptions.cs | 15 ++++ .../ReleaseGroup/ReleaseCommandGroup.cs | 10 +++ .../Program.cs | 2 +- 28 files changed, 138 insertions(+), 43 deletions(-) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches/BranchesCommandGroup.cs => BranchGroup/BranchCommandGroup.cs} (59%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Info/InfoBranchesCommand.cs (89%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Info/InfoBranchesOptions.cs (81%) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/List/ListBranchesCommand.cs (93%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/List/ListBranchesOptions.cs (80%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Pull/PullBranchCommand.cs (79%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Pull/PullBranchOptions.cs (75%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Push/PushBranchCommand.cs (81%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Push/PushBranchOptions.cs (90%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Update/UpdateBranchesCommand.cs (96%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Branches => BranchGroup}/Update/UpdateBranchesOptions.cs (67%) delete mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features/FeaturesCommandGroup.cs => FeatureGroup/FeatureCommandGroup.cs} (60%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/FeatureFinishFailedException.cs (80%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/FinishFeatureCommand.cs (91%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/FinishFeatureData.cs (91%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/FinishFeatureOptions.cs (86%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/FinishFeatureSteps.cs (98%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Finish/IFinishFeatureSteps.cs (78%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/ServiceCollectionExtensions.cs (72%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Start/StartFeatureCommand.cs (96%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Start/StartFeatureData.cs (65%) rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/{Features => FeatureGroup}/Start/StartFeatureOptions.cs (85%) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs similarity index 59% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs index 6ff1fd5..d4f9283 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/BranchesCommandGroup.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs @@ -2,9 +2,9 @@ [assembly: CliCommandGroup(["branch"], "Commands for branches")] -namespace CreativeCoders.GitTool.Cli.Commands.Branches; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup; -public static class BranchesCommandGroup +public static class BranchCommandGroup { public const string Name = "branch"; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs similarity index 89% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs index 063e5ef..ba7adec 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs @@ -5,10 +5,10 @@ using JetBrains.Annotations; using Spectre.Console; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Info; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Info; [UsedImplicitly] -[CliCommand([BranchesCommandGroup.Name, "info"], Description = "Shows information about the current branch")] +[CliCommand([BranchCommandGroup.Name, "info"], Description = "Shows information about the current branch")] public class InfoBranchesCommand(IAnsiConsole ansiConsole, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs similarity index 81% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs index 7e0914f..9ea9a4b 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Info/InfoBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Info; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Info; [PublicAPI] public class InfoBranchesOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs new file mode 100644 index 0000000..722f78d --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs @@ -0,0 +1,8 @@ +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; + +public enum BranchLocation +{ + All, + Local, + Remote +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs similarity index 93% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs index c9faefb..79b513d 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs @@ -6,10 +6,10 @@ using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; [UsedImplicitly] -[CliCommand([BranchesCommandGroup.Name, "list"], Description = "Lists all branches")] +[CliCommand([BranchCommandGroup.Name, "list"], Description = "Lists all branches")] public class ListBranchesCommand(ISysConsole sysConsole, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs similarity index 80% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs index b457c0a..1a3fd4a 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/ListBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; [PublicAPI] public class ListBranchesOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs similarity index 79% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs index d18fed6..69a1791 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs @@ -4,10 +4,10 @@ using JetBrains.Annotations; using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Pull; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Pull; [UsedImplicitly] -[CliCommand([BranchesCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] +[CliCommand([BranchCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] public class PullBranchCommand(IGitToolPullCommand pullCommand, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs similarity index 75% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs index fdeb39d..480c0b4 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Pull/PullBranchOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Pull; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Pull; [PublicAPI] public class PullBranchOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs similarity index 81% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs index fc3d308..e36cc65 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs @@ -4,10 +4,10 @@ using JetBrains.Annotations; using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Push; [UsedImplicitly] -[CliCommand([BranchesCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] +[CliCommand([BranchCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository gitRepository) : ICliCommand { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs similarity index 90% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs index 3383731..2a7e92a 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Push/PushBranchOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Push; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Push; [PublicAPI] public class PushBranchOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs similarity index 96% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs index 1108531..254e371 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs @@ -9,10 +9,10 @@ using Spectre.Console; using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Update; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Update; [UsedImplicitly] -[CliCommand([BranchesCommandGroup.Name, "update"], +[CliCommand([BranchCommandGroup.Name, "update"], Description = "Update all permanent local branches by pulling from remote branches")] public class UpdateBranchesCommand( IRepositoryConfigurations repositoryConfigurations, diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs similarity index 67% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs index 5a3e5de..969a41d 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/Update/UpdateBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Branches.Update; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Update; public class UpdateBranchesOptions { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs deleted file mode 100644 index 24b359c..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Branches/List/BranchLocation.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CreativeCoders.GitTool.Cli.Commands.Branches.List; - -public enum BranchLocation -{ - All, - Local, - Remote -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs similarity index 60% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs index 804dd32..80f0fe6 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/FeaturesCommandGroup.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs @@ -2,9 +2,9 @@ [assembly: CliCommandGroup(["feature"], "Commands for managing features")] -namespace CreativeCoders.GitTool.Cli.Commands.Features; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup; -public static class FeaturesCommandGroup +public static class FeatureCommandGroup { public const string Name = "feature"; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs similarity index 80% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs index a9ffbb9..e99744b 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FeatureFinishFailedException.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs @@ -1,6 +1,6 @@ using CreativeCoders.Cli.Hosting.Exceptions; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public class FeatureFinishFailedException : CliExitException { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs similarity index 91% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs index b979d90..50148a6 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs @@ -5,10 +5,10 @@ using JetBrains.Annotations; using Spectre.Console; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; [UsedImplicitly] -[CliCommand([FeaturesCommandGroup.Name, "finish"], Description = "Finish a feature branch and create a pull request")] +[CliCommand([FeatureCommandGroup.Name, "finish"], Description = "Finish a feature branch and create a pull request")] public class FinishFeatureCommand( IAnsiConsole ansiConsole, IRepositoryConfigurations repositoryConfigurations, diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs similarity index 91% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs index b705997..b29afd9 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public class FinishFeatureData { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs similarity index 86% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs index 7093bc1..0f59f69 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; [PublicAPI] public class FinishFeatureOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs similarity index 98% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs index 33068e3..ee7de64 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/FinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs @@ -6,7 +6,7 @@ using CreativeCoders.SysConsole.Core.Abstractions; using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public class FinishFeatureSteps( ISysConsole sysConsole, diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs similarity index 78% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs index b9c385e..08c2f58 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Finish/IFinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs @@ -1,4 +1,4 @@ -namespace CreativeCoders.GitTool.Cli.Commands.Features.Finish; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public interface IFinishFeatureSteps { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs similarity index 72% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs index 165dc8b..dc85bc6 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/ServiceCollectionExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using CreativeCoders.GitTool.Cli.Commands.Features.Finish; +using CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace CreativeCoders.GitTool.Cli.Commands.Features; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup; public static class ServiceCollectionExtensions { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs similarity index 96% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs index 332c0bb..39750bc 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs @@ -8,10 +8,10 @@ using JetBrains.Annotations; using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; [UsedImplicitly] -[CliCommand([FeaturesCommandGroup.Name, "start"], Description = "Start a new feature branch")] +[CliCommand([FeatureCommandGroup.Name, "start"], Description = "Start a new feature branch")] public class StartFeatureCommand( ISysConsole sysConsole, IRepositoryConfigurations repositoryConfigurations, diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs similarity index 65% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs index ec9e12f..cd0b8db 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs @@ -1,6 +1,4 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; public class StartFeatureData(string featureBranch, string defaultBranch) { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs similarity index 85% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs index 9dc4497..7f2c09b 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Features/Start/StartFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Cli.Commands.Features.Start; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; [PublicAPI] public class StartFeatureOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs new file mode 100644 index 0000000..4361f5e --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs @@ -0,0 +1,72 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.Git.Abstractions.Branches; +using CreativeCoders.GitTool.Base; +using CreativeCoders.SysConsole.Core.Abstractions; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; + +[UsedImplicitly] +[CliCommand([ReleaseCommandGroup.Name, "create"], + Description = "Creates a release by creating a version tag")] +public class CreateReleaseCommand( + ISysConsole sysConsole, + IGitServiceProviders gitServiceProviders, + IGitRepository gitRepository) + : ICliCommand +{ + private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); + + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); + + private async Task MergeDevelopToMain(IGitRepository repository, string mainBranchName, + CreateReleaseOptions options) + { + var provider = await _gitServiceProviders.GetServiceProviderAsync(repository, null); + + var createPullRequest = new GitCreatePullRequest(repository.Info.RemoteUri, + $"Release {options.Version}", "develop", mainBranchName); + + _ = await provider.CreatePullRequestAsync(createPullRequest); + } + + public async Task ExecuteAsync(CreateReleaseOptions options) + { + var mainBranchName = GitBranchNames.Local.GetCanonicalName(gitRepository.Info.MainBranch); + + if (gitRepository.Branches["develop"] != null) + { + _sysConsole.WriteLine( + $"Repository has a develop branch. So first a merge from develop -> {mainBranchName} must be done."); + + await MergeDevelopToMain(gitRepository, mainBranchName, options); + } + + var tagName = $"v{options.Version}"; + + _sysConsole.WriteLine($"Create tag '{tagName}'"); + + gitRepository.Branches.CheckOut(mainBranchName); + + gitRepository.Pull(); + + var versionTag = gitRepository.Tags.CreateTagWithMessage(tagName, mainBranchName, $"Version {options.Version}"); + + if (options.PushAllTags) + { + _sysConsole.WriteLine("Push all tags to remote"); + + gitRepository.Tags.PushAllTags(); + } + else + { + _sysConsole.WriteLine($"Push tag '{versionTag.Name.Canonical}'"); + + gitRepository.Tags.PushTag(versionTag); + } + + return CommandResult.Success; + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs new file mode 100644 index 0000000..9d37fb3 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs @@ -0,0 +1,15 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; + +[PublicAPI] +public class CreateReleaseOptions +{ + private const string PushAllTagsLongName = "alltags"; + + [OptionValue(0, IsRequired = true)] public string? Version { get; set; } + + [OptionParameter('a', PushAllTagsLongName)] + public bool PushAllTags { get; set; } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs new file mode 100644 index 0000000..47405f7 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["release"], "Commands for managing releases")] + +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup; + +public static class ReleaseCommandGroup +{ + public const string Name = "release"; +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs index 09ff48d..b86bf87 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -6,7 +6,7 @@ using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Cli.Commands.Features; +using CreativeCoders.GitTool.Cli.Commands.FeatureGroup; using CreativeCoders.GitTool.Cli.Commands.Shared; using CreativeCoders.GitTool.Cli.Commands.Tool; using CreativeCoders.GitTool.GitHub; From c578afef330cf28356b1285b19d048bcb6d820f7 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Sat, 31 Jan 2026 18:23:03 +0100 Subject: [PATCH 7/7] Add `SetupCommand` for repository configuration and refactor `ShowConfigCommand` - Introduce `SetupCommand` to configure repository settings and service providers. - Refactor `ShowConfigCommand` namespace for consistency. - Update dependency injection to handle repository configurations and certificate validation. --- .../Tool/Setup/SetupCommand.cs | 63 +++++++++++++++++++ .../{ => ShowConfig}/ShowConfigCommand.cs | 2 +- .../Program.cs | 28 ++++++++- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs rename source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/{ => ShowConfig}/ShowConfigCommand.cs (95%) diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs new file mode 100644 index 0000000..d44a811 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs @@ -0,0 +1,63 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.SysConsole.Core; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Tool.Setup; + +[UsedImplicitly] +[CliCommand(["setup"], Description = "Setup the git tool for the current repository")] +public class SetupCommand( + IAnsiConsole ansiConsole, + IGitRepository gitRepository, + IRepositoryConfigurations repositoryConfigurations, + IGitServiceProviders gitServiceProviders) : ICliCommand +{ + public async Task ExecuteAsync() + { + var configuration = repositoryConfigurations.GetConfiguration(gitRepository); + + ansiConsole.PrintBlock() + .WriteLine() + .WriteLine("Development branch (empty = no development branch)"); + + var developBranch = + 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( + $"Prefix for feature branches (Empty = current value '{configuration.FeatureBranchPrefix}'): ") + { AllowEmpty = true }); + + if (!string.IsNullOrEmpty(featureBranchPrefix)) + { + configuration.FeatureBranchPrefix = featureBranchPrefix; + } + + var selectionPrompt = new SelectionPrompt(); + + var gitProviderName = + await ansiConsole.PromptAsync(selectionPrompt.AddChoices(gitServiceProviders.ProviderNames)); + + if (!string.IsNullOrEmpty(gitProviderName)) + { + configuration.GitServiceProviderName = gitProviderName; + } + + var disableCertValidationPrompt = new ConfirmationPrompt("Disable certificate check (true/false): ") + { DefaultValue = configuration.DisableCertificateValidation }; + + configuration.DisableCertificateValidation = await ansiConsole.PromptAsync(disableCertValidationPrompt); + + await repositoryConfigurations.SaveConfigurationAsync(gitRepository.Info.RemoteUri, configuration); + + return CommandResult.Success; + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs similarity index 95% rename from source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs index 3d81437..1199a80 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfigCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs @@ -5,7 +5,7 @@ using CreativeCoders.SysConsole.Core; using Spectre.Console; -namespace CreativeCoders.GitTool.Cli.Commands.Tool; +namespace CreativeCoders.GitTool.Cli.Commands.Tool.ShowConfig; [CliCommand(["showconfig"], Description = "Shows the current repository configuration")] public class ShowConfigCommand( diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs index b86bf87..9aa4b72 100644 --- a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -9,6 +9,7 @@ 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; using Microsoft.Extensions.Configuration; @@ -39,8 +40,7 @@ private static void ConfigureServices(IServiceCollection services) services.Configure(configuration.GetSection("tool")); - services.TryAddSingleton(sp => - sp.GetRequiredService().OpenRepositoryFromCurrentDir()); + ConfigureGitRepository(services); services.AddGitFeatureCommands(); @@ -55,6 +55,30 @@ private static void ConfigureServices(IServiceCollection services) services.AddSysConsole(); } + private static void ConfigureGitRepository(IServiceCollection services) + { + services.TryAddSingleton(sp => + { + var gitRepository = sp.GetRequiredService().OpenRepositoryFromCurrentDir(); + + var repositoryConfigurations = sp.GetRequiredService(); + + var repoConfiguration = repositoryConfigurations.GetConfiguration(gitRepository); + + if (repoConfiguration.DisableCertificateValidation) + { + gitRepository.CertificateCheck = (_, args) => + { + args.IsValid = true; + return true; + }; + } + + return gitRepository; + }); + } + + private static IConfiguration AddConfiguration(IServiceCollection services) { var configurationBuilder = new ConfigurationBuilder();