-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-GITCommand.ps1
More file actions
89 lines (88 loc) · 3.11 KB
/
Invoke-GITCommand.ps1
File metadata and controls
89 lines (88 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function Invoke-GITCommand {
Param (
[Parameter(Mandatory=$true)]
[string]$Command
,
[Parameter(Mandatory=$false)]
[string]$Message
,
[Parameter(Mandatory=$false)]
[int]$SubStepLevel = 0
,
[Parameter(Mandatory=$false)]
[string]$WorkingDirectory
,
[Parameter(Mandatory=$false)]
[switch]$Passthru
,
[Parameter(Mandatory=$false)]
[switch]$NoLog
)
$ParamsGeneral = @{}
$ParamsLevel = @{}
if ( [boolean]$Message ) {
$ParamsGeneral.Add( 'Message', $Message )
}
else {
$ParamsGeneral.Add( 'Message', $Command )
}
if ( [boolean]$SubStepLevel ) {
$ParamsGeneral.Add( 'SubStepLevel', $SubStepLevel )
$ParamsLevel.Add( 'SubStepLevel', $SubStepLevel )
}
$ProcessParams = @{
FilePath = 'git'
ArgumentList = $Command
}
if ( [boolean]$WorkingDirectory ) {
$ProcessParams.Add( 'WorkingDirectory', $WorkingDirectory )
}
$res = Start-ProcessAdv @ProcessParams
if ( -not $NoLog ) {
if ( $res.ExitCode -eq 0 ) {
Write-Log -Status OK @ParamsGeneral
}
else {
$CommandPart = @( $Command -split ' ' )[0]
switch ( $CommandPart ) {
'config' {
switch ( $res.ExitCode ) {
1 {
Write-Log -Status ERROR @ParamsGeneral
Write-Log -Message "The section or key is invalid" -Status ERROR @ParamsLevel
}
2 {
Write-Log -Status ERROR @ParamsGeneral
Write-Log -Message "no section or name was provided" -Status ERROR @ParamsLevel
}
3 {
Write-Log -Status ERROR @ParamsGeneral
Write-Log -Message "the config file is invalid" -Status ERROR @ParamsLevel
}
4 {
Write-Log -Status ERROR @ParamsGeneral
Write-Log -Message "the config file cannot be written" -Status ERROR @ParamsLevel
}
5 {
Write-Log -Status WARN @ParamsGeneral
Write-Log -Message "you try to unset an option which does not exist" -Status WARN @ParamsLevel
}
6 {
Write-Log -Status ERROR @ParamsGeneral
Write-Log -Message "you try to use an invalid regexp" -Status ERROR @ParamsLevel
}
}
}
}
if ( [boolean]( $res.StdErr ) ) {
Write-Log -Message $res.StdErr -Status ERROR @ParamsLevel
}
elseif ( [boolean]( $res.StdOut ) ) {
Write-Log -Message $res.StdOut -Status ERROR @ParamsLevel
}
}
}
if ( $Passthru ) {
return $res
}
}