feat: Add GitRepoRegistration cmdlets #5
1 changed files with 20 additions and 13 deletions
chore(git-provider): Code style
commit
93717b4e43
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue
todo: Document public method