1
0
mirror of https://github.com/fleschutz/PowerShell.git synced 2025-04-12 04:58:19 +02:00

Fix cherry-picker.ps1

This commit is contained in:
Markus Fleschutz 2021-07-07 11:06:45 +02:00
parent 1995c56a2a
commit ecdb447493

View File

@ -9,38 +9,40 @@ param($CommitID = "", $CommitMessage = "", $Branches = "", $RepoDir = "$PWD")
if ($CommitID -eq "" ) { $CommitID = read-host "Enter the commit id to cherry-pick" } if ($CommitID -eq "" ) { $CommitID = read-host "Enter the commit id to cherry-pick" }
if ($CommitMessage -eq "" ) { $CommitMessage = read-host "Enter the commit message to use" } if ($CommitMessage -eq "" ) { $CommitMessage = read-host "Enter the commit message to use" }
if ($Branches -eq "" ) { $Branches = read-host "Enter the target branches" } if ($Branches -eq "" ) { $Branches = read-host "Enter the target branches separated by spaces" }
try { try {
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir" set-location "$RepoDir"
$Branches = $Branches.Split(' ')
foreach($Branch in $Branches) { foreach($Branch in $Branches) {
"STEP: Switching to branch $Branch (git checkout)..." "Switching to branch $Branch (git checkout)..."
& git checkout --recurse-submodules --force $Branch & git checkout --recurse-submodules --force $Branch
if ($lastExitCode -ne "0") { throw "'git checkout' failed" } if ($lastExitCode -ne "0") { throw "'git checkout' failed" }
"STEP: Updating submodules (git submodule update)..." "Updating submodules (git submodule update)..."
& git submodule update --init --recursive & git submodule update --init --recursive
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" } if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
"STEP: Cleaning the repository (git clean -fdx)..." "Cleaning the repository (git clean -fdx)..."
& git clean -fdx & git clean -fdx -f
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" } if ($lastExitCode -ne "0") { throw "'git clean' failed" }
& git submodule foreach --recursive git clean -fdx & git submodule foreach --recursive git clean -fdx -f
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" } if ($lastExitCode -ne "0") { throw "'git clean' in submodules failed" }
"STEP: Pulling latest updates (git pull)..." "Pulling latest updates (git pull)..."
& git pull --recurse-submodules & git pull --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git pull' failed" } if ($lastExitCode -ne "0") { throw "'git pull' failed" }
"STEP: Checking the status (git status)..." "Checking the status (git status)..."
$Result = (git status) $Result = (git status)
if ($lastExitCode -ne "0") { throw "'git status' failed" } if ($lastExitCode -ne "0") { throw "'git status' failed" }
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Branch is NOT clean: $Result" } if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Branch is NOT clean: $Result" }
"Cherry-picking and committing..."
& git cherry-pick --no-commit "$CommitID" & git cherry-pick --no-commit "$CommitID"
if ($lastExitCode -ne "0") { throw "'git cherry-pick $CommitID' failed" } if ($lastExitCode -ne "0") { throw "'git cherry-pick $CommitID' failed" }