Skip to content

Instantly share code, notes, and snippets.

@coderoffortune
Last active May 3, 2017 07:48
Show Gist options
  • Save coderoffortune/21693585b18b9bc349be4295ed21c449 to your computer and use it in GitHub Desktop.
Save coderoffortune/21693585b18b9bc349be4295ed21c449 to your computer and use it in GitHub Desktop.
A script to automate branches closure in mercurial
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
}
}
@coderoffortune
Copy link
Author

In order to enable script execution the command below should be run once inside Powershell:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment