diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitRepoRegistrationManager.cs
similarity index 94%
rename from src/ModuleCore/Git/GitManager.cs
rename to src/ModuleCore/Git/GitRepoRegistrationManager.cs
index f16a313..1ade336 100644
--- a/src/ModuleCore/Git/GitManager.cs
+++ b/src/ModuleCore/Git/GitRepoRegistrationManager.cs
@@ -6,15 +6,17 @@ using SQLite;
namespace ModuleCore.Git;
-// TODO: better name for this
-public class GitManager
+///
+/// Manages git repo registration, including creating any registration persistence via a backing
+///
+public class GitRepoRegistrationManager
{
- private static readonly Lazy GitManagerInstance = new(() => new GitManager());
+ private static readonly Lazy GitManagerInstance = new(() => new GitRepoRegistrationManager());
private static Action? _debugWriterDelegate;
private readonly DatabaseManager _db;
private readonly ConcurrentDictionary _registrations;
- private GitManager(string? databaseName = null)
+ private GitRepoRegistrationManager(string? databaseName = null)
{
_registrations = new ConcurrentDictionary();
// Regular usage of this constructor will never pass a database name in. Currently only tests should be hitting
@@ -25,15 +27,15 @@ public class GitManager
}
///
- /// Returns the current instance. If no instance has been created, returns a new instance
+ /// Returns the current instance. If no instance has been created, returns a new instance
/// and then the same instance every call after.
///
- public static GitManager Instance => GitManagerInstance.Value;
+ public static GitRepoRegistrationManager Instance => GitManagerInstance.Value;
///
/// Always returns a new clean instance of GitManager
///
- internal static GitManager InternalFreshInstance(string databaseName) => new(databaseName);
+ internal static GitRepoRegistrationManager InternalFreshInstance(string databaseName) => new(databaseName);
///
/// Deletes the underlying database file.
diff --git a/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs
index 1b5f193..506aee2 100644
--- a/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs
+++ b/src/PowershellModule/Git/Commands/GetGitRepoRegistrationCommand.cs
@@ -13,7 +13,7 @@ public class GetGitRepoRegistrationCommand : PSCmdlet
{
protected override void BeginProcessing()
{
- var repos = GitManager.Instance.ListRepos();
+ var repos = GitRepoRegistrationManager.Instance.ListRepos();
WriteObject(repos);
diff --git a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs
index 47578dd..9e0729f 100644
--- a/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs
+++ b/src/PowershellModule/Git/Commands/NewGitRepoRegistrationCommand.cs
@@ -17,19 +17,19 @@ public sealed class NewGitRepoRegistrationCommand : PSCmdlet
{
try
{
- GitManager.SetDebugWriter(WriteDebug);
+ GitRepoRegistrationManager.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);
+ var repoFolder = GitRepoRegistrationManager.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();
+ GitRepoRegistrationManager.Instance.RegisterRepo(repoFolder.Directory, Name ?? repoFolder.Folder);
+ GitRepoRegistrationManager.ClearDebugWriter();
base.BeginProcessing();
}
diff --git a/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs
index bfd1834..a79060e 100644
--- a/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs
+++ b/src/PowershellModule/Git/Commands/RemoveGitRepoRegistrationCommand.cs
@@ -17,21 +17,21 @@ public class RemoveGitRepoRegistrationCommand : PSCmdlet
{
try
{
- GitManager.SetDebugWriter(WriteDebug);
+ GitRepoRegistrationManager.SetDebugWriter(WriteDebug);
// If we aren't given a value for the Name argument, default behaviour is to attempt to remove a registration
// by the current git repo folder name for the current location.
// If we have a name, don't bother testing for a git repo, just attempt to remove the registration by name
// regardless of where we're being called from
var registrationNameToRemove = string.IsNullOrEmpty(Name)
- ? GitManager.IsGitRepo(SessionState.Path.CurrentLocation.Path).Folder
+ ? GitRepoRegistrationManager.IsGitRepo(SessionState.Path.CurrentLocation.Path).Folder
: Name;
- GitManager.Instance.UnregisterRepo(registrationNameToRemove);
+ GitRepoRegistrationManager.Instance.UnregisterRepo(registrationNameToRemove);
// Removing a registration works similar to registering a new one - we either remove by exact name, or by
// the folder if no name is given (so a user can remove a registration from a git repo they're currently in)
- GitManager.ClearDebugWriter();
+ GitRepoRegistrationManager.ClearDebugWriter();
base.BeginProcessing();
}
diff --git a/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs b/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs
index 4300f71..e4eb647 100644
--- a/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs
+++ b/src/PowershellModule/Git/Commands/ShowGitRepoRegistrationCommand.cs
@@ -21,7 +21,7 @@ public class ShowGitRepoRegistrationCommand : PSCmdlet
protected override void BeginProcessing()
{
- var location = GitManager.Instance.GetDirectoryForRegisteredRepo(Name);
+ var location = GitRepoRegistrationManager.Instance.GetDirectoryForRegisteredRepo(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.
diff --git a/tests/ModuleTests/Git/AddRegistrationTests.cs b/tests/ModuleTests/Git/AddRegistrationTests.cs
index 883e595..c862773 100644
--- a/tests/ModuleTests/Git/AddRegistrationTests.cs
+++ b/tests/ModuleTests/Git/AddRegistrationTests.cs
@@ -23,7 +23,7 @@ public class AddRegistrationTests
public Task BasicRepoRegistration((int testId, string path) testData)
{
Settings.UseFileName($"{nameof(BasicRepoRegistration)}_{testData.testId}");
- var gitManager = GitManager.InternalFreshInstance(nameof(BasicRepoRegistration));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(BasicRepoRegistration));
try
{
@@ -44,7 +44,7 @@ public class AddRegistrationTests
public void RepoRegistrationWithEmptyName()
{
Settings.UseFileName(nameof(RepoRegistrationWithEmptyName));
- var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithEmptyName));
var testRepoAbsolutePath = "Test:/some/test/repo";
try
@@ -63,7 +63,7 @@ public class AddRegistrationTests
public void RepoRegistrationWithNullName()
{
Settings.UseFileName(nameof(RepoRegistrationWithNullName));
- var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithNullName));
var testRepoAbsolutePath = "Test:/some/test/repo";
try
{
@@ -84,7 +84,7 @@ public class AddRegistrationTests
{
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
- var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
var testRepoAbsolutePath = "Test:/some/test/repo";
try
{
@@ -102,7 +102,7 @@ public class AddRegistrationTests
public void DuplicateRepoRegistrationShouldFail()
{
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
- var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
var testRepoAbsolutePath = "Test:/some/test/repo";
string[] paths = ["test", "nested", "path"];
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
@@ -110,7 +110,6 @@ public class AddRegistrationTests
try
{
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
- // TODO: make nested registrations fail in both directions and test
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
Assert.Equal(Path.Combine(paths), firstRegistration);
@@ -128,7 +127,7 @@ public class AddRegistrationTests
public void DuplicateRepoRegistrationDifferentSlashShouldNotFail()
{
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
- var gitManager = GitManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
+ var gitManager = GitRepoRegistrationManager.InternalFreshInstance(nameof(RepoRegistrationWithWhitespaceName));
var testRepoAbsolutePath = "Test:/some/test/repo";
string[] paths = ["test", "nested", "path"];
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
@@ -136,7 +135,6 @@ public class AddRegistrationTests
try
{
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
- // TODO: make nested registrations fail in both directions and test
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
var differentPathSeparatorRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator);