-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.ps1
52 lines (45 loc) · 1.18 KB
/
push.ps1
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
# push script
# This script file is supposed to do git add, commit and push operations
# in the specified locations.
#
# Requires: git, powershell 5.0 or higher
#Requires -Version 5.0
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0)]
[string]$Message = $null,
[Parameter(Mandatory = $false)]
[string[]]$Target = @("warpdl", "warplib")
)
function Invoke-GitOperation {
& git add .
if (![string]::IsNullOrEmpty($Message)) {
& git commit -am $Message
}
else {
& git commit
}
& git push
}
if ($Target.Count -ne 0) {
$script:originalPWD = $PWD
for ($i = 0; $i -lt $Target.Count; $i++) {
try {
$Target[$i] = Resolve-Path -Path $Target[$i] -ErrorAction "Stop"
}
catch {
Write-Output "Couldn't resolve location '$($Target[$i])'"
$Target[$i] = ''
continue
}
}
foreach ($currentTargetPath in $Target) {
Set-Location -Path $currentTargetPath > $null
Invoke-GitOperation
}
Set-Location -Path $script:originalPWD > $null
}
else {
# just do it here
Invoke-GitOperation
}