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
This commit is contained in:
parent
164df4ecf4
commit
7b59b90572
1 changed files with 8 additions and 12 deletions
|
|
@ -15,22 +15,15 @@ public sealed class NewGitRepoCommand : PSCmdlet
|
||||||
HelpMessage = "Reference name for the repo")]
|
HelpMessage = "Reference name for the repo")]
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
public NewGitRepoCommand()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void BeginProcessing()
|
protected override void BeginProcessing()
|
||||||
{
|
{
|
||||||
var pwd = this.SessionState.Path.CurrentLocation.Path;
|
|
||||||
WriteDebug("Checking if current directory is a git repository...");
|
|
||||||
|
|
||||||
GitManager.SetDebugWriter(WriteDebug);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -52,12 +45,13 @@ public sealed class NewGitRepoCommand : PSCmdlet
|
||||||
|
|
||||||
private ParsedGitFolderDetails? IsGitRepo(string path)
|
private ParsedGitFolderDetails? IsGitRepo(string path)
|
||||||
{
|
{
|
||||||
|
WriteDebug("Checking if current directory is a git repository...");
|
||||||
|
|
||||||
var ps = new ProcessStartInfo("git",
|
var ps = new ProcessStartInfo("git",
|
||||||
["rev-parse", "--show-toplevel"])
|
["-C", path, "rev-parse", "--show-toplevel"])
|
||||||
{
|
{
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = 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
|
// 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
|
// Gotta trim what we get as it might already have a newline character at the end
|
||||||
var dirInfo = new DirectoryInfo(directory.Trim());
|
var dirInfo = new DirectoryInfo(directory.Trim());
|
||||||
|
|
||||||
|
WriteDebug("...location is a git repo (duh).");
|
||||||
|
|
||||||
var repoFolderInfo = new ParsedGitFolderDetails
|
var repoFolderInfo = new ParsedGitFolderDetails
|
||||||
{
|
{
|
||||||
Directory = dirInfo.FullName,
|
Directory = dirInfo.FullName,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue