mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-20 00:48:17 +02:00
Update cherry-picker.ps1
This commit is contained in:
parent
83aa3ab77f
commit
480dc16e64
@ -8,6 +8,7 @@ check-swap-space.ps1, checks the swap space for free space left
|
|||||||
check-symlinks.ps1, checks every symlink in the given directory tree
|
check-symlinks.ps1, checks every symlink in the given directory tree
|
||||||
check-windows-system-files.ps1, checks the validity of the Windows system files
|
check-windows-system-files.ps1, checks the validity of the Windows system files
|
||||||
check-xml-file.ps1, checks the given XML file for validity
|
check-xml-file.ps1, checks the given XML file for validity
|
||||||
|
cherry-picker.ps1, cherry-picks a Git commit into multiple branches
|
||||||
clean-branch.ps1, cleans the current Git branch (including submodules) from generated files
|
clean-branch.ps1, cleans the current Git branch (including submodules) from generated files
|
||||||
clone-repos.ps1, clones well-known Git repositories
|
clone-repos.ps1, clones well-known Git repositories
|
||||||
close-calculator.ps1, closes the calculator program gracefully
|
close-calculator.ps1, closes the calculator program gracefully
|
||||||
|
|
@ -101,6 +101,7 @@ Collection of PowerShell Scripts
|
|||||||
|
|
||||||
📝 Scripts for Git
|
📝 Scripts for Git
|
||||||
-----------------
|
-----------------
|
||||||
|
* [cherry-picker.ps1](Scripts/cherry-picker.ps1) - cherry-picks a Git commit into multiple branches
|
||||||
* [clean-branch.ps1](Scripts/clean-branch.ps1) - cleans the current Git branch (including submodules) from generated files
|
* [clean-branch.ps1](Scripts/clean-branch.ps1) - cleans the current Git branch (including submodules) from generated files
|
||||||
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
|
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
|
||||||
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git user configuration
|
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git user configuration
|
||||||
|
@ -1,50 +1,64 @@
|
|||||||
# Cherry-picks a commit ID from main branch to all the other branches
|
#!/bin/powershell
|
||||||
$CommitID = "1234"
|
<#
|
||||||
$CommitMessage = "Update rules for .gitignore file (cherry-picked from main branch)"
|
.SYNTAX ./cherry-picker.ps1 [<commit-id>] [<commit-message>] [<branches>] [<repo-dir>]
|
||||||
$RepoDir = "D:\Repos\ufa"
|
.DESCRIPTION cherry-picks a Git commit into multiple branches
|
||||||
$Branches = "attower_bugfix_14.43.x", "attower_bugfix_14.42.x", "attower_bugfix_14.41.x", "attower_bugfix_14.40.x", "attower_bugfix_14.39.x", "attower_bugfix_14.38.x", "attower_bugfix_14.37.x", "attower_bugfix_14.36.x", "attower_bugfix_14.35.x", "attower_bugfix_14.34.x", "attower_bugfix_14.33.x", "attower_bugfix_14.32.x", "attower_bugfix_14.31.x", "attower_bugfix_14.30.x", "attower_bugfix_14.29.x", "attower_bugfix_14.27.x", "attower_bugfix_14.26.x", "attower_bugfix_14.25.x", "attower_bugfix_14.24.x", "attower_bugfix_14.23.x", "attower_bugfix_14.22.x", "attower_bugfix_14.21.x", "attower_bugfix_14.20.x", "attower_bugfix_14.19.x", "attower_bugfix_14.18.x", "attower_bugfix_14.17.x", "attower_bugfix_14.16.x", "attower_bugfix_14.15.x", "attower_bugfix_14.13.x", "attower_bugfix_14.11.x", "attower_bugfix_14.10.x", "attower_bugfix_14.9.x", "attower_bugfix_14.8.x", "attower_bugfix_14.6.x", "attower_bugfix_14.5.x", "attower_bugfix_14.4.x"
|
.LINK https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES Author: Markus Fleschutz / License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param($CommitID = "", $CommitMessage = "", $Branches = "", $RepoDir = "$PWD")
|
||||||
|
|
||||||
|
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 ($Branches -eq "" ) {
|
||||||
|
$Branches = read-host "Enter the target branches"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
set-location "$RepoDir"
|
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||||
|
set-location "$RepoDir"
|
||||||
|
|
||||||
foreach($Branch in $Branches) {
|
foreach($Branch in $Branches) {
|
||||||
|
|
||||||
"STEP: Switching to branch $Branch (git checkout)..."
|
"STEP: 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)..."
|
"STEP: 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)..."
|
"STEP: Cleaning the repository (git clean -fdx)..."
|
||||||
& git clean -fdx
|
& git clean -fdx
|
||||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
|
if ($lastExitCode -ne "0") { throw "'git clean -fdx' failed" }
|
||||||
|
|
||||||
& git submodule foreach --recursive git clean -fdx
|
& git submodule foreach --recursive git clean -fdx
|
||||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
|
if ($lastExitCode -ne "0") { throw "'git clean -fdx' in submodules failed" }
|
||||||
|
|
||||||
"STEP: Pulling latest updates (git pull)..."
|
"STEP: 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)..."
|
"STEP: 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" }
|
||||||
|
|
||||||
& 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" }
|
||||||
|
|
||||||
& git commit -m "$CommitMessage"
|
& git commit -m "$CommitMessage"
|
||||||
if ($lastExitCode -ne "0") { throw "'git commit' failed" }
|
if ($lastExitCode -ne "0") { throw "'git commit' failed" }
|
||||||
|
|
||||||
& git push
|
& git push
|
||||||
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
||||||
}
|
}
|
||||||
|
"DONE."
|
||||||
"DONE."
|
exit 0
|
||||||
exit 0
|
|
||||||
} catch {
|
} catch {
|
||||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user