From 7b59b905720fa694bd5cff6836ecccc9b41d1fed Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 24 Aug 2026 17:10:20 +1000 Subject: [PATCH] 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 --- .../Git/Commands/NewGitRepoCommand.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs index 9be33a4..29f629a 100644 --- a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs @@ -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,