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 7b59b90572 - Show all commits

chore(git-provider): Use -C when checking if current directory is a git repo

- move WriteDebug to IsGitRepo
- inline variable for SessionState.Path.CurrentLocation.Path
Scott 2026-08-24 17:10:20 +10:00

View file

@ -15,22 +15,15 @@ public sealed class NewGitRepoCommand : PSCmdlet
HelpMessage = "Reference name for the repo")]
public string? Name { get; set; }
public NewGitRepoCommand()
{
}
protected override void BeginProcessing()
{
var pwd = this.SessionState.Path.CurrentLocation.Path;
WriteDebug("Checking if current directory is a git repository...");
GitManager.SetDebugWriter(WriteDebug);
var repoFolfder = IsGitRepo(pwd);
var repoFolder = IsGitRepo(SessionState.Path.CurrentLocation.Path);
if (repoFolfder is not null)
if (repoFolder is not null)
{
GitManager.Instance.RegisterRepo(repoFolfder.Directory, Name ?? repoFolfder.Folder);
GitManager.Instance.RegisterRepo(repoFolder.Directory, Name ?? repoFolder.Folder);
}
else
{
@ -52,12 +45,13 @@ public sealed class NewGitRepoCommand : PSCmdlet
private ParsedGitFolderDetails? IsGitRepo(string path)
{
WriteDebug("Checking if current directory is a git repository...");
var ps = new ProcessStartInfo("git",
["rev-parse", "--show-toplevel"])
["-C", path, "rev-parse", "--show-toplevel"])
{
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = path
};
// If the user doesn't have git on their path, this will throw an exception that I don't have to do anything
@ -79,6 +73,8 @@ public sealed class NewGitRepoCommand : PSCmdlet
// Gotta trim what we get as it might already have a newline character at the end
var dirInfo = new DirectoryInfo(directory.Trim());
WriteDebug("...location is a git repo (duh).");
var repoFolderInfo = new ParsedGitFolderDetails
{
Directory = dirInfo.FullName,