From 8f6009de0f28278ffefdbff56e90fff9db636877 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 5 Jan 2017 10:00:48 -0800 Subject: [PATCH] Add initial script to aid in cherrypicking from devel to stable-2.2 --- hacking/cherrypick.py | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 hacking/cherrypick.py diff --git a/hacking/cherrypick.py b/hacking/cherrypick.py new file mode 100755 index 00000000000..ad55dc84fe4 --- /dev/null +++ b/hacking/cherrypick.py @@ -0,0 +1,52 @@ +#!/usr/bin/python3 + +import os +import sys +import tempfile + +import sh + +REPO_PATH = {'extras': '/srv/ansible/stable-2.2/lib/ansible/modules/extras', + 'core': '/srv/ansible/stable-2.2/lib/ansible/modules/core'} + +if __name__ == '__main__': + commit_hash = sys.argv[1] + which_modules = sys.argv[2] + git = sh.git.bake('--no-pager', _tty_out=False) + try: + # Get the change + git('checkout', 'devel') + patch = git('format-patch', '-1', '--stdout', commit_hash).stdout + finally: + git('checkout', '-') + + # Transform the change for the new repo + patch = patch.replace(b'lib/ansible/modules/', b'') + new_patch = [] + patch_stream = (l for l in patch.split(b'\n')) + for line in patch_stream: + if line.strip() == b'---': + new_patch.append(b'(cherry picked from %s)' % commit_hash.encode('utf-8')) + new_patch.append(line) + break + new_patch.append(line) + new_patch.extend(list(patch_stream)) + + # Save the patch + try: + fh, patchfilename = tempfile.mkstemp() + os.write(fh, b'\n'.join(new_patch)) + os.close(fh) + + # Apply the patch + try: + orig_dir = os.getcwd() + os.chdir(REPO_PATH[which_modules]) + git('am', patchfilename) + finally: + os.chdir(orig_dir) + except: + print("Problem occurred. Patch saved in: {}".format(patchfilename)) + else: + os.remove(patchfilename) +