feat: Add GitRepoRegistration cmdlets #5

Merged
pascal_nulah merged 69 commits from feature/git-provider into dev 2026-09-06 09:33:36 +10:00
Showing only changes of commit 93717b4e43 - Show all commits

chore(git-provider): Code style

Scott 2026-08-24 14:24:10 +10:00

View file

@ -8,13 +8,6 @@ namespace ModuleCore.Git;
public class GitManager
{
private static readonly Lazy<GitManager> GitManagerInstance = new(() => new GitManager());
public static GitManager Instance => GitManagerInstance.Value;
/// <summary>
/// Always returns a new clean instance of GitManager
/// </summary>
internal static GitManager InternalFreshInstance => new();
private readonly ConcurrentDictionary<string, InternalGitRegistration> _registrations;
private GitManager()
@ -24,8 +17,15 @@ public class GitManager
_registrations = new ConcurrentDictionary<string, InternalGitRegistration>();
}
public static GitManager Instance => GitManagerInstance.Value;
/// <summary>
/// Registers a git repository based on an absolute location. If <paramref name="registrationName"/> is null or empty,
/// Always returns a new clean instance of GitManager
/// </summary>
internal static GitManager InternalFreshInstance => new();
/// <summary>
/// Registers a git repository based on an absolute location. If <paramref name="registrationName" /> is null or empty,
/// the registration will use the folder name for the git repo at the top level.
/// </summary>
/// <param name="absoluteRepositoryLocation"></param>
@ -37,7 +37,7 @@ public class GitManager
? new DirectoryInfo(absoluteRepositoryLocation).Name
: registrationName;
if (_registrations.TryAdd(registrationName, new InternalGitRegistration()
if (_registrations.TryAdd(registrationName, new InternalGitRegistration
{
Name = registrationName,
Location = absoluteRepositoryLocation,
@ -51,7 +51,15 @@ public class GitManager
public List<GitRegistration> ListRepos()
{
return _registrations.Select(x => new GitRegistration() { Name = x.Value.Name, Location = x.Value.Location, CurrentBranch = x.Value.CurrentBranch }).ToList();
return _registrations.Select(x =>
new GitRegistration
{
Name = x.Value.Name,
Location = x.Value.Location,
CurrentBranch = x.Value.CurrentBranch,
}
)
.ToList();
}
public string GetRepo(string? registeredName)
pascal_nulah marked this conversation as resolved

todo: Document public method

todo: Document public method
@ -74,13 +82,12 @@ public class GitManager
/// </summary>
private class InternalGitRegistration
{
private string _currentBranch = string.Empty;
private long _nextCheckTime;
public required string Name { get; set; }
public required string Location { get; set; }
public string CurrentBranch => GetCurrentBranch();
private string _currentBranch = string.Empty;
private long _nextCheckTime;
// TODO: not fully decided on if I want this feature or not, but keeping it in for now
private string GetCurrentBranch()
{