-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-push.ps1
More file actions
83 lines (66 loc) · 1.37 KB
/
run-push.ps1
File metadata and controls
83 lines (66 loc) · 1.37 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
# push.ps1
$ErrorActionPreference = 'Stop'
function Read-YesNo([string]$Prompt)
{
while ($true)
{
$raw = Read-Host "$Prompt [y/N]"
$raw = ($raw ?? '').Trim()
if ([string]::IsNullOrWhiteSpace($raw))
{
return $false
}
switch ($raw.ToLowerInvariant())
{
{ $_ -in @('y', 'yes') } { return $true }
{ $_ -in @('n', 'no') } { return $false }
default { Write-Host "Please answer y or n." }
}
}
}
function Read-NonEmpty([string]$Prompt)
{
while ($true)
{
$value = (Read-Host $Prompt)
$value = ($value ?? '').Trim()
if (-not [string]::IsNullOrWhiteSpace($value))
{
return $value
}
Write-Host "Value cannot be empty."
}
}
try
{
git fetch --all --prune | Out-Host
$status = (git status --porcelain)
if (-not [string]::IsNullOrWhiteSpace($status))
{
git status --porcelain | Out-Host
throw "Working tree is not clean."
}
$mergeBase = (git merge-base HEAD origin/develop).Trim()
if ([string]::IsNullOrWhiteSpace($mergeBase))
{
throw "Could not determine merge-base with origin/develop."
}
$commitCount = [int](git rev-list --count "$mergeBase..HEAD")
if ($commitCount -le 0)
{
exit 0
}
if (-not (Read-YesNo "Proceed?"))
{
exit 0
}
$msg = Read-NonEmpty "Message"
git reset --soft $mergeBase | Out-Host
git commit -m $msg | Out-Host
git push | Out-Host
}
catch
{
Write-Host "ERROR: $($_.Exception.Message)"
exit 1
}