Read about our upcoming Code of Conduct on this issue

Commit 09ac4055 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

convert-git-tags-push: made a main() function

parent b41a332ca430
......@@ -39,13 +39,14 @@
check_call(('hg', 'revert', '.hgtags'))
parser = argparse.ArgumentParser(
description="Copy Git tags in Mercurial global tags."
)
parser.add_argument("-s", "--simulate", action="store_true",
help="Don't commit nor push, rollback changes "
"to the tags file instead.")
parser.add_argument("--logging-level", default='INFO')
parser.add_argument("-R", "--repository", default=".",
help="Mercurial repository to operate on.")
def main():
parser = argparse.ArgumentParser(
description="Copy Git tags in Mercurial global tags."
)
parser.add_argument("-s", "--simulate", action="store_true",
help="Don't commit nor push, rollback changes "
"to the tags file instead.")
parser.add_argument("--logging-level", default='INFO')
parser.add_argument("-R", "--repository", default=".",
help="Mercurial repository to operate on.")
......@@ -51,6 +52,6 @@
cl_args = parser.parse_args()
repo = cl_args.repository
simulate = cl_args.simulate
logging.basicConfig(level=getattr(logging, cl_args.logging_level.upper()))
cl_args = parser.parse_args()
repo = cl_args.repository
simulate = cl_args.simulate
logging.basicConfig(level=getattr(logging, cl_args.logging_level.upper()))
......@@ -56,7 +57,15 @@
os.chdir(repo)
dirty = check_output(('hg', 'status', '-mard')).strip()
if dirty:
logger.error("Repository %r has local modifications. Aborting.", repo)
sys.exit(1)
os.chdir(repo)
dirty = check_output(('hg', 'status', '-mard')).strip()
if dirty:
logger.error("Repository %r has local modifications. Aborting.", repo)
sys.exit(1)
logger.info("Updating repository %r to the %r branch",
repo, GIT_TAGS_BRANCH)
check_call(('hg', 'update', "-q", GIT_TAGS_BRANCH))
logger.info("Importing Git tags as local modifications")
shutil.copy2(os.path.join('.hg', 'git-tags'),
os.path.join('.hgtags'))
......@@ -62,4 +71,10 @@
logger.info("Updating repository %r to the %r branch", repo, GIT_TAGS_BRANCH)
check_call(('hg', 'update', "-q", GIT_TAGS_BRANCH))
logger.info("Displaying the diff.")
sys.stderr.flush()
diff = check_output(('hg', 'diff'))
if not(diff.strip()):
logger.warning("Empty diff, nothing to do, see you next time.")
sys.exit(0)
remote = check_output(('hg', 'config', 'paths.default')).strip().decode()
sys.stdout.buffer.write(diff)
......@@ -65,5 +80,8 @@
logger.info("Importing Git tags as local modifications")
shutil.copy2(os.path.join('.hg', 'git-tags'),
os.path.join('.hgtags'))
confirmation = input("Commit and push those changes to '%s'?\n"
"Please enter 'YES' to confirm: " % remote)
if confirmation.strip() != 'YES':
revert()
logger.warning("Not confirmed, changes reverted. Bye")
sys.exit(0)
......@@ -69,10 +87,9 @@
logger.info("Displaying the diff.")
sys.stderr.flush()
diff = check_output(('hg', 'diff'))
if not(diff.strip()):
logger.warning("Empty diff, nothing to do, see you next time.")
sys.exit(0)
remote = check_output(('hg', 'config', 'paths.default')).strip().decode()
sys.stdout.buffer.write(diff)
if simulate:
logger.info("Simulation mode: reverting .hgtags")
revert()
logger.info("Simulation mode: current working directory is %s",
os.getcwd())
helper = Helper(simulate)
......@@ -78,9 +95,16 @@
confirmation = input("Commit and push those changes to '%s'?\n"
"Please enter 'YES' to confirm: " % remote)
if confirmation.strip() != 'YES':
revert()
logger.warning("Not confirmed, changes reverted. Bye")
sys.exit(0)
helper.log_info("committing the changes")
helper.check_call(
('hg', 'commit',
'-m', "Updated Mercurial tags from Git tags",
'.hgtags'))
helper.log_info("pushing")
helper.check_call(('hg', 'push', '-r', '.'))
if simulate:
logger.warning("End of simulation, hope you enjoyed it. Bye")
else:
logger.warning("Changes committed and pushed. Bye")
......@@ -85,21 +109,4 @@
if simulate:
logger.info("Simulation mode: reverting .hgtags")
revert()
logger.info("Simulation mode: current working directory is %s",
os.getcwd())
helper = Helper(simulate)
helper.log_info("committing the changes")
helper.check_call(
('hg', 'commit', '-m', "Updated Mercurial tags from Git tags", '.hgtags'))
helper.log_info("pushing")
helper.check_call(('hg', 'push', '-r', '.'))
if simulate:
logger.warning("End of simulation, hope you enjoyed it. Bye")
else:
logger.warning("Changes committed and pushed. Bye")
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment