Created
November 3, 2016 15:26
-
-
Save togakangaroo/6716670af9efe2655b1ae80b115f570d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
from subprocess import check_output | |
# Originally from http://stackoverflow.com/questions/23122183/can-you-close-a-mercurial-branch-without-updating-to-it-first | |
def close_branch( branch, message ): | |
if not message: | |
message = 'Closing branch "{}"'.format( branch ) | |
print( 'Closing branch "{}"'.format( branch ) ) | |
try: | |
check_output( 'hg debugsetparent ' + branch ) | |
check_output( 'hg branch ' + branch ) | |
check_output( 'hg commit --close-branch -X * -m "' + message + '"' ) | |
except: | |
print( 'Failed to close branch.' ) | |
def main(): | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('branch', help='branch name(s)', nargs = '+' ) | |
parser.add_argument('-m', '--message', help='message (defaults to "Closing branch <branch name>")' ) | |
args = parser.parse_args() | |
status = check_output( 'hg status' ) | |
if len(status) > 0: | |
print( 'Do not use this script with local changes. Commit/revert changes and try again' ) | |
exit(1) | |
# Cache initial revision and branch. | |
initial_revision = check_output( 'hg id -i -b' ).split() | |
# print( 'Using: ' + initial_revision[0].decode("utf-8") ) | |
for branch in args.branch: | |
close_branch( branch, args.message ) | |
# Return to original changeset | |
check_output( 'hg debugsetparent ' + initial_revision[0].decode("utf-8") ) | |
check_output( 'hg branch ' + initial_revision[1].decode("utf-8") ) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment