-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolve-Rebase.ps1
More file actions
60 lines (47 loc) · 1.59 KB
/
Resolve-Rebase.ps1
File metadata and controls
60 lines (47 loc) · 1.59 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
function Resolve-Rebase {
param ([string]$repoPath)
$gitDir = Join-Path $repoPath ".git"
if ((Test-Path "$gitDir\rebase-merge") -or
(Test-Path "$gitDir\rebase-apply")) {
Write-Host "Rebase detected in $repoPath ...aborting, possibly just remove git subfolders rebase-merge or rebase-apply" -ForegroundColor Red
Set-Location $repoPath
git rebase --abort
}
}
function Invoke-SafePull {
param ([string]$repoPath)
Set-Location $repoPath
$hasChanges = git status --porcelain
$stashed = $false
if ($hasChanges) {
Write-Host "Stashing changes in $repoPath" -ForegroundColor Green
git stash push -m "auto-script-stash"
$stashed = $true
}
git fetch
$local = git rev-parse HEAD
$remote = git rev-parse "@{u}"
$base = git merge-base HEAD "@{u}"
if ($local -eq $remote) {
Write-Host "Up to date"
}
elseif ($local -eq $base) {
Write-Host "Fast-forwarding"
git merge --ff-only "@{u}"
}
else {
Write-Host "Diverged → skipping $repoPath" -ForegroundColor Yellow
}
if ($stashed) {
Write-Host "Re-applying stash in $repoPath" -ForegroundColor Green
git stash apply --quiet
if ($LASTEXITCODE -ne 0) {
Write-Host "Conflict during stash apply!" -ForegroundColor Red
} else {
git stash drop
}
if (git diff --name-only --diff-filter=U) {
Write-Host "Unresolved conflicts remain!" -ForegroundColor Red
}
}
}