mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-23 14:18:38 +01:00
Improve cherry-picker.ps1 and list-cli-tools.ps1
This commit is contained in:
parent
1da9bf6cb3
commit
f7d5d366f7
@ -1,10 +1,11 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
cherry-picker.ps1 [<commit-id>] [<commit-message>] [<branches>] [<repo-dir>]
|
||||
.DESCRIPTION
|
||||
Cherry-picks a Git commit into multiple branches
|
||||
Cherry-picks a Git commit into one or more branches (branch names need to be separated by spaces).
|
||||
NOTE: in case of merge conflicts the script stops immediately!
|
||||
.EXAMPLE
|
||||
PS> .\cherry-picker.ps1 93849f889 "Fix typo" v1 v2 v3
|
||||
PS> .\cherry-picker.ps1 93849f889 "Fix typo" "v1 v2 v3"
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -14,51 +15,57 @@
|
||||
param([string]$CommitID = "", [string]$CommitMessage = "", [string]$Branches = "", [string]$RepoDir = "$PWD")
|
||||
|
||||
try {
|
||||
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 separated by spaces" }
|
||||
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
|
||||
$Branches = $Branches.Split(' ')
|
||||
foreach($Branch in $Branches) {
|
||||
if ($CommitID -eq "") { $CommitID = read-host "Enter the Git 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 branches (separated by spaces)" }
|
||||
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
|
||||
"Switching to branch $Branch (git checkout)..."
|
||||
$BranchArray = $Branches.Split(" ")
|
||||
$NumBranches = $BranchArray.Count
|
||||
foreach($Branch in $BranchArray) {
|
||||
|
||||
"🍒 Switching to branch $Branch ..."
|
||||
& git checkout --recurse-submodules --force $Branch
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout' failed" }
|
||||
if ($lastExitCode -ne "0") { throw "'git checkout $Branch' failed" }
|
||||
|
||||
"Updating submodules (git submodule update)..."
|
||||
"🍒 Updating submodules..."
|
||||
& git submodule update --init --recursive
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
||||
|
||||
"Cleaning the repository (git clean -fdx)..."
|
||||
"🍒 Cleaning the repository from untracked files..."
|
||||
& git clean -fdx -f
|
||||
if ($lastExitCode -ne "0") { throw "'git clean' failed" }
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx -f' failed" }
|
||||
|
||||
& git submodule foreach --recursive git clean -fdx -f
|
||||
if ($lastExitCode -ne "0") { throw "'git clean' in submodules failed" }
|
||||
if ($lastExitCode -ne "0") { throw "'git clean -fdx -f' in submodules failed" }
|
||||
|
||||
"Pulling latest updates (git pull)..."
|
||||
"🍒 Pulling latest updates..."
|
||||
& git pull --recurse-submodules
|
||||
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
||||
|
||||
"Checking the status (git status)..."
|
||||
"🍒 Checking the status..."
|
||||
$Result = (git status)
|
||||
if ($lastExitCode -ne "0") { throw "'git status' failed" }
|
||||
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Branch is NOT clean: $Result" }
|
||||
|
||||
"Cherry-picking and committing..."
|
||||
"🍒 Cherry picking..."
|
||||
& git cherry-pick --no-commit "$CommitID"
|
||||
if ($lastExitCode -ne "0") { throw "'git cherry-pick $CommitID' failed" }
|
||||
|
||||
"🍒 Committing..."
|
||||
& git commit -m "$CommitMessage"
|
||||
if ($lastExitCode -ne "0") { throw "'git commit' failed" }
|
||||
|
||||
"🍒 Pushing..."
|
||||
& git push
|
||||
if ($lastExitCode -ne "0") { throw "'git push' failed" }
|
||||
}
|
||||
"DONE."
|
||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||
"✔️ cherry picked $CommitID into $NumBranches branches in $Elapsed sec"
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -17,10 +17,13 @@ function CheckFor { param([string]$Cmd, [string]$VersionArg)
|
||||
$Version = $Info.Version
|
||||
$Location = $Info.Source
|
||||
if ($Version -eq "0.0.0.0") {
|
||||
$Result = invoke-expression "$Location $VersionArg"
|
||||
if ($Result -match '\d+\.\d+') {
|
||||
$Version = "$($Matches[0])"
|
||||
} else {
|
||||
if ("$VersionArg" -ne "") {
|
||||
$Result = invoke-expression "$Location $VersionArg"
|
||||
if ($Result -match '\d+\.\d+') {
|
||||
$Version = "$($Matches[0])"
|
||||
} else {
|
||||
$Version = "?"
|
||||
} else
|
||||
$Version = "?"
|
||||
}
|
||||
}
|
||||
@ -85,7 +88,7 @@ function ListTools {
|
||||
CheckFor regedit "--version"
|
||||
CheckFor replace "--version"
|
||||
CheckFor robocopy "--version"
|
||||
CheckFor rsh "--version"
|
||||
CheckFor rsh ""
|
||||
CheckFor rsync "--version"
|
||||
CheckFor rundll32 "--version"
|
||||
CheckFor scp "--version"
|
||||
|
Loading…
Reference in New Issue
Block a user