-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Invoke-Git to use System.Diagnostics.Process
- Loading branch information
Showing
10 changed files
with
493 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<# | ||
.SYNOPSIS | ||
Invokes the git command. | ||
.PARAMETER WorkingDirectory | ||
The path to the git working directory. | ||
.PARAMETER Timeout | ||
Seconds to wait for process to exit. | ||
.PARAMETER Arguments | ||
The arguments to pass to the Git executable. | ||
.EXAMPLE | ||
Invoke-Git clone https://github.com/X-Guardian/xActiveDirectory.wiki.git --quiet | ||
Invokes the Git executable to clone the specified repository to the current working directory. | ||
#> | ||
|
||
function Invoke-Git | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$WorkingDirectory, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[System.Int32] | ||
$TimeOut = 120, | ||
|
||
[Parameter(ValueFromRemainingArguments = $true)] | ||
[System.String[]] | ||
$Arguments | ||
) | ||
|
||
$returnValue = @{ | ||
'ExitCode' = -1 | ||
'StandardOutput' = '' | ||
'StandardError' = '' | ||
} | ||
|
||
$argumentsJoined = $Arguments -join ' ' | ||
|
||
# Trying to remove any access token from the debug output. | ||
if ($argumentsJoined -match ':[\d|a-f].*@') | ||
{ | ||
$argumentsJoined = $argumentsJoined -replace ':[\d|a-f].*@', ':RedactedToken@' | ||
} | ||
|
||
Write-Debug -Message ($localizedData.InvokingGitMessage -f $argumentsJoined) | ||
|
||
try | ||
{ | ||
$process = New-Object -TypeName System.Diagnostics.Process | ||
$process.StartInfo.Arguments = $Arguments | ||
$process.StartInfo.CreateNoWindow = $true | ||
$process.StartInfo.FileName = 'git.exe' | ||
$process.StartInfo.RedirectStandardOutput = $true | ||
$process.StartInfo.RedirectStandardError = $true | ||
$process.StartInfo.UseShellExecute = $false | ||
$process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden | ||
$process.StartInfo.WorkingDirectory = $WorkingDirectory | ||
|
||
if ($process.Start() -eq $true) | ||
{ | ||
if ($process.WaitForExit($TimeOut) -eq $true) | ||
{ | ||
$returnValue.ExitCode = $process.ExitCode | ||
$returnValue.StandardOutput = $process.StandardOutput.ReadToEnd() | ||
$returnValue.StandardError = $process.StandardError.ReadToEnd() | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
throw $_ | ||
} | ||
finally | ||
{ | ||
if ($process) | ||
{ | ||
$process.Dispose() | ||
} | ||
} | ||
|
||
return $returnValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.