-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitCommit.ps1
More file actions
88 lines (67 loc) · 2.04 KB
/
GitCommit.ps1
File metadata and controls
88 lines (67 loc) · 2.04 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
param (
[string]$message = "auto-commit"
)
$parent_directory = Get-Location
. .\Resolve-Rebase.ps1
function Has-Conflicts {
return (git diff --name-only --diff-filter=U)
}
function Has-Changes {
return (git status --porcelain)
}
function Has-Upstream {
git rev-parse --abbrev-ref "@{u}" 2>$null | Out-Null
return ($LASTEXITCODE -eq 0)
}
Get-ChildItem -Recurse -Directory | ForEach-Object {
$directory = $_.FullName
if (Test-Path "$directory\.git") {
Write-Host "Processing $directory"
Set-Location $directory
Resolve-Rebase $directory
# Skip if no upstream (optional but safer)
if (-not (Has-Upstream)) {
Write-Host "Skipping (no upstream configured)" -ForegroundColor Yellow
return
}
# Skip if conflicts exist
if (Has-Conflicts) {
Write-Host "Skipping (merge conflicts present)" -ForegroundColor Red
return
}
# Skip if nothing to commit
if (-not (Has-Changes)) {
Write-Host "No changes"
return
}
git add .
# Double-check conflicts after staging (edge case safety)
if (Has-Conflicts) {
Write-Host "Skipping after add (conflicts detected)" -ForegroundColor Red
return
}
git commit -m $message
}
}
# Root repo
Set-Location $parent_directory
Resolve-Rebase $parent_directory
if (Has-Upstream) {
if (Has-Conflicts) {
Write-Host "Skipping root (merge conflicts present)" -ForegroundColor Red
}
elseif (Has-Changes) {
git add .
if (Has-Conflicts) {
Write-Host "Skipping root after add (conflicts detected)" -ForegroundColor Red
} else {
git commit -m $message
}
}
else {
Write-Host "No changes in root repo"
}
} else {
Write-Host "Root repo has no upstream → skipping" -ForegroundColor Yellow
}
Set-Location $parent_directory