From af5c9e43b6d378a8c9b4d3ffb2fd3b606f80d31a Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 23 Aug 2026 09:25:45 +1000 Subject: [PATCH 1/3] feat(git-provider): Initial Get-GitRepo implementation --- src/ModuleCore/Git/GitManager.cs | 11 +++++++++++ .../Git/Commands/GetGitRepoCommand.cs | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/PowershellModule/Git/Commands/GetGitRepoCommand.cs diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index fe1f69e..ce03922 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -52,4 +52,15 @@ public class GitManager throw new Exception($"Git repo already registered with the name {registrationName}"); } + + public List ListRepos() + { + return _registrations.Select(x => new GitReg() { Name = x.Value.Name, Location = x.Value.Location }).ToList(); + } +} + +public class GitReg +{ + public required string Name { get; set; } + public required string Location { get; set; } } \ No newline at end of file diff --git a/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs b/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs new file mode 100644 index 0000000..c1a4cb6 --- /dev/null +++ b/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs @@ -0,0 +1,19 @@ +using System.Management.Automation; +using ModuleCore.Git; + +namespace PowershellModule.Git.Commands; + +[Cmdlet(VerbsCommon.Get, Noun)] +public class ListGitRepoCommand : PSCmdlet +{ + private const string Noun = "GitRepo"; + + protected override void BeginProcessing() + { + var repos = GitManager.Instance.ListRepos(); + + WriteObject(repos); + + base.BeginProcessing(); + } +} \ No newline at end of file From 740d35d3e759a986f6856c1f89e6ffcbad32e806 Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 23 Aug 2026 09:53:33 +1000 Subject: [PATCH 2/3] feat(git-provider): Initial Show-GitRepo implementation --- src/ModuleCore/Git/GitManager.cs | 15 +++++++ .../Git/Commands/ShowGitRepoCommand.cs | 45 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index ce03922..702d0e1 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -57,6 +57,21 @@ public class GitManager { return _registrations.Select(x => new GitReg() { Name = x.Value.Name, Location = x.Value.Location }).ToList(); } + + public string GetRepo(string? registeredName) + { + if (string.IsNullOrEmpty(registeredName)) + { + throw new Exception("Name cannot be null"); + } + + if (_registrations.TryGetValue(registeredName, out var registration)) + { + return registration.Location; + } + + throw new Exception($"No git repo has been registered with the name {registeredName}"); + } } public class GitReg diff --git a/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs b/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs new file mode 100644 index 0000000..116062c --- /dev/null +++ b/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs @@ -0,0 +1,45 @@ +using System; +using System.Management.Automation; +using ModuleCore.Git; + +namespace PowershellModule.Git.Commands; + +[Cmdlet(VerbsCommon.Show, Noun)] +public class ShowGitRepoCommand : PSCmdlet +{ + private const string Noun = "GitRepo"; + + [Parameter( + Position = 0, + ValueFromPipeline = true, + Mandatory = true, + HelpMessage = "Reference name for the repo")] + public string? Name { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "Changes directory directly instead of using Set-Location")] + [Alias("NoSetLocation")] + public SwitchParameter NoStack { get; set; } + + protected override void BeginProcessing() + { + var location = GitManager.Instance.GetRepo(Name); + + // By default instead of doing the same as cd, we instead do pushd so a user can popd straight back to where + // they came from. + // TODO: incorporate this into the custom prompt when I develop that + if (!NoStack) + { + // Push the current location to the stack + // TODO: support named stacks. PowerShell *-Location commands support named stacks, but I don't personally + // use them myself so I haven't implemented them initially. I would like to in the future though, but right + // now it's low value to me. + // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-7.6#example-4-set-the-current-location-to-a-named-stack + SessionState.Path.PushCurrentLocation(null); + } + + SessionState.Path.SetLocation(location); + base.BeginProcessing(); + } +} \ No newline at end of file From 48ad65e86cac0db65109e5914bedca430a65133d Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 23 Aug 2026 09:58:16 +1000 Subject: [PATCH 3/3] refactor(git-provider): Centralise *-GitRepo noun name --- src/PowershellModule/Git/Commands/GetGitRepoCommand.cs | 4 +--- src/PowershellModule/Git/Commands/GitCommands.cs | 6 ++++++ src/PowershellModule/Git/Commands/NewGitRepoCommand.cs | 4 +--- src/PowershellModule/Git/Commands/SetGitRepoCommand.cs | 5 ++--- src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs | 4 +--- 5 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 src/PowershellModule/Git/Commands/GitCommands.cs diff --git a/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs b/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs index c1a4cb6..1859375 100644 --- a/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs @@ -3,11 +3,9 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -[Cmdlet(VerbsCommon.Get, Noun)] +[Cmdlet(VerbsCommon.Get, GitCommands.GitRepoNoun)] public class ListGitRepoCommand : PSCmdlet { - private const string Noun = "GitRepo"; - protected override void BeginProcessing() { var repos = GitManager.Instance.ListRepos(); diff --git a/src/PowershellModule/Git/Commands/GitCommands.cs b/src/PowershellModule/Git/Commands/GitCommands.cs new file mode 100644 index 0000000..2d5c888 --- /dev/null +++ b/src/PowershellModule/Git/Commands/GitCommands.cs @@ -0,0 +1,6 @@ +namespace PowershellModule.Git.Commands; + +public class GitCommands +{ + public const string GitRepoNoun = "GitRepo"; +} \ No newline at end of file diff --git a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs index ba56252..5aabd59 100644 --- a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs @@ -6,11 +6,9 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -[Cmdlet(VerbsCommon.New, Noun)] +[Cmdlet(VerbsCommon.New, GitCommands.GitRepoNoun)] public sealed class NewGitRepoCommand : PSCmdlet { - private const string Noun = "GitRepo"; - [Parameter( Position = 0, ValueFromPipeline = true, diff --git a/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs b/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs index 4ccb140..69c4a34 100644 --- a/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs @@ -4,11 +4,10 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -[Cmdlet(VerbsCommon.Set, Noun)] +// TODO: decide if I want to use this verb instead of show. Currently this implementation is under Show-GitRepo +[Cmdlet(VerbsCommon.Set, GitCommands.GitRepoNoun)] public class SetGitRepoCommand : PSCmdlet { - private const string Noun = "GitRepo"; - public SetGitRepoCommand() { Console.WriteLine($"{nameof(NewGitRepoCommand)} init"); diff --git a/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs b/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs index 116062c..3394ef3 100644 --- a/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs @@ -4,11 +4,9 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -[Cmdlet(VerbsCommon.Show, Noun)] +[Cmdlet(VerbsCommon.Show, GitCommands.GitRepoNoun)] public class ShowGitRepoCommand : PSCmdlet { - private const string Noun = "GitRepo"; - [Parameter( Position = 0, ValueFromPipeline = true,