-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.ps1
More file actions
41 lines (36 loc) · 1.12 KB
/
Copy pathpush.ps1
File metadata and controls
41 lines (36 loc) · 1.12 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
param (
[Parameter(Mandatory = $true)]
[string]$CommitMessage,
[string]$DetailedMessage
)
if (!(Get-Command git.exe -ErrorAction SilentlyContinue)) {
Write-Error "Git is not installed or not on the PATH."
exit 1
}
function Run-GitCommand {
param (
[Parameter(Mandatory = $true)]
[string]$Command,
[string[]]$Arguments,
[string]$ErrorMessage
)
try {
& $Command @Arguments
if ($LASTEXITCODE -ne 0) {
Write-Error $ErrorMessage
exit 1
}
} catch {
Write-Error "$ErrorMessage`n$($_.Exception.Message)"
exit 1
}
}
Run-GitCommand -Command "git" -Arguments "add", "." -ErrorMessage "Error: git add failed."
$commitArgs = @("commit", "-m", $CommitMessage)
if ($DetailedMessage) {
$commitArgs += "-m"
$commitArgs += $DetailedMessage
}
Run-GitCommand -Command "git" -Arguments $commitArgs -ErrorMessage "Error: git commit failed."
Run-GitCommand -Command "git" -Arguments "pull" -ErrorMessage "Error: git pull failed."
Run-GitCommand -Command "git" -Arguments "push" -ErrorMessage "Error: git push failed."