Public Access
CertZipDL
This commit is contained in:
+51
-53
@@ -7,15 +7,10 @@
|
||||
|
||||
$Remote = 'https://gitea.hideawaygaming.com.au/jessikitty/visitor-signin.git'
|
||||
|
||||
# git reports failure through its exit code, not as a PowerShell error, so every
|
||||
# call has to be checked. Without this the script reports success after a
|
||||
# rejected push, which is exactly what it used to do.
|
||||
function Invoke-Git {
|
||||
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments)
|
||||
& git @Arguments
|
||||
return $LASTEXITCODE
|
||||
}
|
||||
|
||||
# git is called directly and $LASTEXITCODE checked straight afterwards. Wrapping
|
||||
# it in a function does not work: a PowerShell function returns everything written
|
||||
# to the output stream, so the caller receives git's console output as well as the
|
||||
# exit code, and comparing that array against 0 reports failure every time.
|
||||
function Fail($message) {
|
||||
Write-Host ''
|
||||
Write-Host $message -ForegroundColor Red
|
||||
@@ -27,86 +22,89 @@ if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
Fail 'Git is not installed or not on PATH. Get it from https://git-scm.com/download/win'
|
||||
}
|
||||
|
||||
# Keeps line endings sane between Windows and the Ubuntu docker host.
|
||||
git config --global core.autocrlf input | Out-Null
|
||||
|
||||
# git refuses to commit without an identity, and says so in a way that is easy to
|
||||
# miss among its other output.
|
||||
$who = git config user.email
|
||||
if (-not $who) { $who = git config --global user.email }
|
||||
if (-not $who) {
|
||||
Write-Host 'Git does not know who you are. Set that once:' -ForegroundColor Yellow
|
||||
Write-Host ' git config --global user.email "you@example.com"'
|
||||
Write-Host ' git config --global user.name "Your Name"'
|
||||
Fail 'Nothing was committed.'
|
||||
}
|
||||
|
||||
if (-not (Test-Path '.git')) {
|
||||
Write-Host 'Setting up a new local repository...'
|
||||
if ((Invoke-Git init -b main) -ne 0) { Fail 'git init failed.' }
|
||||
git init -b main
|
||||
if ($LASTEXITCODE -ne 0) { Fail 'git init failed.' }
|
||||
}
|
||||
|
||||
if ((git remote) -match '^origin$') {
|
||||
git remote set-url origin $Remote
|
||||
} else {
|
||||
git remote add origin $Remote
|
||||
}
|
||||
if ((git remote) -match '^origin$') { git remote set-url origin $Remote }
|
||||
else { git remote add origin $Remote }
|
||||
|
||||
# ------------------------------------------------- finish what was started
|
||||
# Whatever branch is checked out, not a hard-coded one. Pushing 'main' while the
|
||||
# work sits on 'deploy' reports "Everything up-to-date" and sends nothing.
|
||||
$branch = (git rev-parse --abbrev-ref HEAD).Trim()
|
||||
if (-not $branch -or $branch -eq 'HEAD') { Fail 'No branch is checked out here.' }
|
||||
Write-Host "Branch: $branch" -ForegroundColor Cyan
|
||||
|
||||
# A rebase or merge left half-done blocks everything that follows, and the error
|
||||
# git gives is easy to mistake for a push problem. Catch it here and say plainly
|
||||
# what to do.
|
||||
$gitDir = (git rev-parse --git-dir 2>$null)
|
||||
# ------------------------------------------- an unfinished rebase blocks everything
|
||||
|
||||
$gitDir = git rev-parse --git-dir 2>$null
|
||||
if ($gitDir) {
|
||||
$stuck = @('rebase-merge', 'rebase-apply', 'MERGE_HEAD', 'CHERRY_PICK_HEAD') |
|
||||
Where-Object { Test-Path (Join-Path $gitDir $_) }
|
||||
if ($stuck) {
|
||||
Write-Host ''
|
||||
Write-Host 'There is an unfinished rebase or merge in this folder.' -ForegroundColor Red
|
||||
Write-Host 'Nothing else can happen until it is settled. Your options:' -ForegroundColor Yellow
|
||||
Write-Host ''
|
||||
Write-Host ' git rebase --abort throw the attempt away and go back to how things were'
|
||||
Write-Host ' git status see which files still need attention'
|
||||
Write-Host ' git rebase --continue after fixing the files git listed'
|
||||
Write-Host ''
|
||||
Write-Host 'If you are unsure, "git rebase --abort" is the safe one. It puts the' -ForegroundColor Yellow
|
||||
Write-Host 'folder back exactly as it was before the rebase started.' -ForegroundColor Yellow
|
||||
exit 1
|
||||
Write-Host 'There is an unfinished rebase or merge here.' -ForegroundColor Red
|
||||
Write-Host ' git rebase --abort throw it away, back to how things were'
|
||||
Write-Host ' git status see which files need attention'
|
||||
Write-Host ' git rebase --continue after fixing those files'
|
||||
Fail 'Nothing was done.'
|
||||
}
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------- commit
|
||||
|
||||
git add -A
|
||||
$pending = git status --porcelain
|
||||
if ($pending) {
|
||||
if (git status --porcelain) {
|
||||
$message = Read-Host 'Describe this change (press enter for a dated default)'
|
||||
if (-not $message) { $message = "Update $(Get-Date -Format 'yyyy-MM-dd HH:mm')" }
|
||||
if ((Invoke-Git commit -m $message) -ne 0) { Fail 'git commit failed.' }
|
||||
git commit -m $message
|
||||
if ($LASTEXITCODE -ne 0) { Fail 'git commit failed. The message above says why.' }
|
||||
Write-Host 'Committed.' -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host 'No file changes to commit. Checking for anything unpushed...' -ForegroundColor Yellow
|
||||
Write-Host 'Nothing new to commit.' -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ------------------------------------------------------- catch up, then push
|
||||
|
||||
Write-Host 'Checking what is on the server...'
|
||||
if ((Invoke-Git fetch origin) -ne 0) {
|
||||
Fail 'Could not reach Gitea. Check the network and your sign in details.'
|
||||
}
|
||||
git fetch origin
|
||||
if ($LASTEXITCODE -ne 0) { Fail 'Could not reach Gitea. Check the network and your sign in details.' }
|
||||
|
||||
if (git ls-remote --heads origin main) {
|
||||
$behind = (git rev-list --count HEAD..origin/main 2>$null)
|
||||
if (git ls-remote --heads origin $branch) {
|
||||
$behind = git rev-list --count "HEAD..origin/$branch" 2>$null
|
||||
if ($behind -and [int]$behind -gt 0) {
|
||||
Write-Host "The server has $behind commit(s) this folder does not. Replaying your work on top..."
|
||||
if ((Invoke-Git pull --rebase origin main) -ne 0) {
|
||||
git pull --rebase origin $branch
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host ''
|
||||
Write-Host 'The two histories could not be joined automatically.' -ForegroundColor Red
|
||||
Write-Host ''
|
||||
Write-Host 'See what is on the server that you do not have:' -ForegroundColor Yellow
|
||||
Write-Host ' git log --oneline HEAD..origin/main'
|
||||
Write-Host ''
|
||||
Write-Host 'If that is nothing you need, and this folder is the good copy:' -ForegroundColor Yellow
|
||||
Write-Host ' git push --force-with-lease origin main'
|
||||
exit 1
|
||||
Write-Host " git log --oneline HEAD..origin/$branch what is on the server"
|
||||
Write-Host " git push --force-with-lease origin $branch if this folder is the good copy"
|
||||
Fail 'Nothing was sent.'
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-Host "Branch '$branch' is not on the server yet; it will be created."
|
||||
}
|
||||
|
||||
if ((Invoke-Git push -u origin main) -ne 0) {
|
||||
Fail 'The push was rejected. Read the message above. Nothing was sent.'
|
||||
}
|
||||
git push -u origin $branch
|
||||
if ($LASTEXITCODE -ne 0) { Fail 'The push was rejected. The message above says why. Nothing was sent.' }
|
||||
|
||||
Write-Host ''
|
||||
Write-Host 'Pushed successfully.' -ForegroundColor Green
|
||||
Write-Host "Pushed $branch successfully." -ForegroundColor Green
|
||||
git log --oneline -1
|
||||
Write-Host 'https://gitea.hideawaygaming.com.au/jessikitty/visitor-signin'
|
||||
|
||||
Reference in New Issue
Block a user