Last active
May 3, 2017 07:48
-
-
Save coderoffortune/21693585b18b9bc349be4295ed21c449 to your computer and use it in GitHub Desktop.
A script to automate branches closure in mercurial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true)][String[]]$branches | |
) | |
# Default catchall branch for closed branches | |
$closureOldBranchName = "CLOSURE_OLD_BRANCH" | |
$closedBranches = @() | |
# Runs a loop on the branches passed as param | |
foreach($branch in $branches) { | |
# Setups comments | |
$closeCommitMsg = "Close " + $branch + " branch" | |
$escapedBranchName = '"{0}"' -f $branch | |
# Checkout into closable branch | |
hg up -c $escapedBranchName | |
# Check if checkout on the branch was successful | |
if($?) | |
{ | |
# Perform the close commit on the branch | |
hg commit --close-branch -m $closeCommitMsg | |
if($?) { | |
$closedBranches += $escapedBranchName | |
} | |
} | |
} | |
# Checkout into the catchall branch for closed ones | |
hg up -c $closureOldBranchName | |
# Check if checkout on catchall branch has been successful | |
if($?) { | |
foreach($closedBranch in $closedBranches) { | |
# Setups comments | |
$mergeClosedCommitMsg = "Merge with " + $closedBranch | |
# Merge the closed branch into this one | |
hg merge --tool internal:local $closedBranch | |
# Commit the changes | |
hg commit -m $mergeClosedCommitMsg | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to enable script execution the command below should be run once inside Powershell:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned