CD / tools /git /push-scope.ps1
tkadkghdlf's picture
Sync from GitHub via hub-sync
f711f7f verified
Raw
History Blame Contribute Delete
800 Bytes
param(
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter(Mandatory = $true)]
[string[]]$Scope,
[string]$Branch
)
$ErrorActionPreference = "Stop"
if (-not $Branch) {
$Branch = (git branch --show-current).Trim()
if (-not $Branch) {
throw "Could not determine current branch."
}
}
foreach ($path in $Scope) {
Write-Host "[push-scope] stage $path"
git add -- $path
if ($LASTEXITCODE -ne 0) {
throw "git add failed for scope: $path"
}
}
git diff --cached --quiet
if ($LASTEXITCODE -eq 0) {
throw "No staged changes in selected scope."
}
git commit -m $Message
if ($LASTEXITCODE -ne 0) {
throw "git commit failed."
}
git push origin $Branch
if ($LASTEXITCODE -ne 0) {
throw "git push failed to branch: $Branch"
}
Write-Host "[push-scope] completed"