From 7c6a47bfcb999a74df20d41dd9873721adf297f0 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 26 Aug 2026 13:16:20 +1000 Subject: [PATCH 1/4] docs(git-provider): Add initial git command documentation - create solution folder for docs --- PowershellModule.slnx | 39 +++++++++++++++++-------------- docs/GitRepositoryRegistration.md | 19 +++++++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 docs/GitRepositoryRegistration.md diff --git a/PowershellModule.slnx b/PowershellModule.slnx index 04cf69b..2f6dd79 100644 --- a/PowershellModule.slnx +++ b/PowershellModule.slnx @@ -1,20 +1,23 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/GitRepositoryRegistration.md b/docs/GitRepositoryRegistration.md new file mode 100644 index 0000000..88e74d3 --- /dev/null +++ b/docs/GitRepositoryRegistration.md @@ -0,0 +1,19 @@ +# Git Repo Registration + +- all commands support `-debug` + +## New-GitRepoRegistration + +`New-GitRepoRegistration [-Name string]` + +## Get-GitRepoRegistration + +`Get-GitRepoRegistration` + +## Show-GitRepoRegistration + +`Show-GitRepoRegistration -Name string [-NoStack|-NoSetLocation]` + +## Remove-GitRepoRegistration + +`Remove-GitRepoRegistration [-Name string]` \ No newline at end of file From 8d64b1aa9ee8cb92eea35ddc3c4171b36a996348 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 26 Aug 2026 13:30:18 +1000 Subject: [PATCH 2/4] fix(git-provider): Return after successful registration removal --- src/ModuleCore/Git/GitManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index dfeb1f7..eeb3b60 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -155,6 +155,7 @@ public class GitManager if (_registrations.TryRemove(registrationName, out var removedItem)) { _debugWriterDelegate?.Invoke($"Removed {registrationName}."); + return; } // Weird error to throw, but by this stage we shouldn't have a git repo registered under this name From 46eeb0cb1ee68387c2a4df6b82c5577b7f1218e7 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 26 Aug 2026 14:16:48 +1000 Subject: [PATCH 3/4] feat(git-provider): Update debug output when registering - output when no name is given - update message when current location is confirmed to be a git repo --- src/ModuleCore/Git/GitManager.cs | 6 +++++- .../Git/Commands/NewGitRepoRegistrationCommand.cs | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index eeb3b60..f301244 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -108,6 +108,7 @@ public class GitManager if (_registrations.TryAdd(registrationName, gitRegistration)) { + _debugWriterDelegate?.Invoke($"Registered '{gitRegistration.Location}' to name '{registrationName}'"); return registrationName; } @@ -196,6 +197,9 @@ public class GitManager /// /// Returns the git root directory for any nested directory if git rev-parse --show-toplevel returns a value. + /// + /// Will always return a non-null value if the directory is a git repo, otherwise an exception will be thrown + /// /// /// Path to check if it or any of its parents contain a git repository /// @@ -236,7 +240,7 @@ public class GitManager // Gotta trim what we get as it might already have a newline character at the end var dirInfo = new DirectoryInfo(directory.Trim()); - _debugWriterDelegate?.Invoke("...location is a git repo (duh)."); + _debugWriterDelegate?.Invoke("...location is a git repo!"); var repoFolderInfo = new ParsedGitFolderDetails { diff --git a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs index 1f968aa..ec460eb 100644 --- a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs +++ b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs @@ -19,8 +19,15 @@ public sealed class NewGitRepoRegistrationCommand : PSCmdlet { GitManager.SetDebugWriter(WriteDebug); + // Test that we're in a git repo first. If we aren't (or git isn't available), this method will throw + // so we don't need to handle for null (yet). var repoFolder = GitManager.IsGitRepo(SessionState.Path.CurrentLocation.Path); + if (string.IsNullOrWhiteSpace(Name)) + { + WriteDebug("No name given for registration, defaulting to git folder root."); + } + GitManager.Instance.RegisterRepo(repoFolder.Directory, Name ?? repoFolder.Folder); GitManager.ClearDebugWriter(); From 5e0e4ad2be44d9463fdd6a8984efd4958540ba09 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 26 Aug 2026 14:17:06 +1000 Subject: [PATCH 4/4] docs(git-provider): Document New-GitRepoRegistration --- docs/GitRepositoryRegistration.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/GitRepositoryRegistration.md b/docs/GitRepositoryRegistration.md index 88e74d3..83038b7 100644 --- a/docs/GitRepositoryRegistration.md +++ b/docs/GitRepositoryRegistration.md @@ -6,6 +6,34 @@ `New-GitRepoRegistration [-Name string]` +Creates a new registration for the current directory, optionally registering against the given name. If `-Name` is not given the folder for the root level of the git repo will be used. + +Name registrations are _not_ case-sensitive, so registrations can be made using different cases for the same location, and multiple registrations can exist for the git repository. + +```pwsh +# Default registration +PS D:/Repos/Project-a> New-GitRepoRegistration -debug +DEBUG: Checking if current directory is a git repository... +DEBUG: ...location is a git repo! +DEBUG: No name given for registration, defaulting to git folder root. +DEBUG: Registered 'D:/Repos/Project-a' to name 'Project-a' + +# Named registration +PS D:/Repos/Project-a> New-GitRepoRegistration "test repo" -debug +DEBUG: Checking if current directory is a git repository... +DEBUG: ...location is a git repo! +DEBUG: Registered 'D:/Repos/Project-a' to name 'test repo' + +PS D:/Repos/Project-a> Get-GitRepoRegistration + +Name Location CurrentBranch +---- -------- ------------- +test-repo D:/Repos/Project-a main +Project-a D:/Repos/Project-a main +``` + +If the current directory is not in a git repo, a registration already exists by name or default folder, or if any other issue occurs such as git not being available an error will be thrown. + ## Get-GitRepoRegistration `Get-GitRepoRegistration`