diff options
author | Stéphane Cerveau <scerveau@collabora.com> | 2021-09-30 12:33:35 +0200 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-10-13 17:03:09 +0000 |
commit | 7256ddb74ad31dd948aa673b407c67c31590a62e (patch) | |
tree | 1aafff02b3c52a825940bb25b0cc2d6353087fa4 /scripts | |
parent | 551239c618923c6ecb16ed1f4583a50275bdd4d8 (diff) | |
download | gstreamer-7256ddb74ad31dd948aa673b407c67c31590a62e.tar.gz |
rebase-branch-from-old: few improvments
- Enhance the documentation
- Allow to revert cherry-pick
- coding style
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1094>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/rebase-branch-from-old-module.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/scripts/rebase-branch-from-old-module.py b/scripts/rebase-branch-from-old-module.py index 2e0dbc73be..30676775f6 100755 --- a/scripts/rebase-branch-from-old-module.py +++ b/scripts/rebase-branch-from-old-module.py @@ -19,11 +19,12 @@ URL = "https://gitlab.freedesktop.org/" PARSER = argparse.ArgumentParser( description="`Rebase` a branch from an old GStreamer module onto the monorepo" ) -PARSER.add_argument("repo", help="The repo with the old module to use.") +PARSER.add_argument("repo", help="The repo with the old module to use. ie https://gitlab.freedesktop.org/user/gst-plugins-bad.git or /home/me/gst-build/subprojects/gst-plugins-bad") PARSER.add_argument("branch", help="The branch to rebase.") log_depth = [] # type: T.List[str] + @contextmanager def nested(name=''): global log_depth @@ -33,18 +34,23 @@ def nested(name=''): finally: log_depth.pop() + def bold(text: str): return f"\033[1m{text}\033[0m" + def green(text: str): return f"\033[1;32m{text}\033[0m" + def red(text: str): return f"\033[1;31m{text}\033[0m" + def yellow(text: str): return f"\033[1;33m{text}\033[0m" + def fprint(msg, nested=True): if log_depth: prepend = log_depth[-1] + ' | ' if nested else '' @@ -128,13 +134,18 @@ class GstCherryPicker: self.git("rebase", f"{module}/master", interaction_message=f"Failed rebasing {remote_name}/{self.branch} on {module}/master with:\n" f" `$ git rebase {module}/master`") - self.cherry_pick(tmpbranchname) - except: + ret = self.cherry_pick(tmpbranchname) + except Exception as e: self.git("rebase", "--abort", can_fail=True) self.git("checkout", prevbranch) self.git("branch", "-D", tmpbranchname) raise - fprint(f"{green(' OK')}\n", nested=False) + if ret: + fprint(f"{green(' OK')}\n", nested=False) + else: + self.git("checkout", prevbranch) + self.git("branch", "-D", tmpbranchname) + fprint(f"{red(' ERROR')}\n", nested=False) def cherry_pick(self, branch): shas = self.git('log', '--format=format:%H', f'{self.module}/master..').strip() @@ -144,13 +155,17 @@ class GstCherryPicker: for sha in reversed(shas.split()): fprint(f' - Cherry picking: {bold(sha)}\n') - self.git("cherry-pick", sha, - interaction_message=f"cherry-picking {sha} onto {branch} with:\n " - f" `$ git cherry-pick {sha}`" - ) - + try: + self.git("cherry-pick", sha, + interaction_message=f"cherry-picking {sha} onto {branch} with:\n " + f" `$ git cherry-pick {sha}`", + revert_operation=["cherry-pick", "--abort"]) + except Exception as e: + fprint(f' - Cherry picking failed: {bold(sha)}\n') + return False + return True - def git(self, *args, can_fail=False, interaction_message=None, call=False): + def git(self, *args, can_fail=False, interaction_message=None, call=False, revert_operation=None): retry = True while retry: retry = False @@ -160,7 +175,7 @@ class GstCherryPicker: return subprocess.check_output(["git"] + list(args), stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT).decode() - except: + except Exception as e: if not can_fail: fprint(f"\n\n{bold(red('ERROR'))}: `git {' '.join(args)}` failed" + "\n", nested=False) raise @@ -181,7 +196,7 @@ class GstCherryPicker: f"You should then exit with the following codes:\n\n" f" - {bold('`exit 0`')}: once you have fixed the problem and we can keep moving the \n" f" - {bold('`exit 1`')}: {bold('retry')}: once you have let the repo in a state where cherry-picking the commit should be to retried\n" - f" - {bold('`exit 3`')}: stop the script and abandon moving your MRs\n" + f" - {bold('`exit 2`')}: stop the script and abandon rebasing your branch\n" "\n```\n", nested=False) try: if os.name == 'nt': @@ -195,9 +210,11 @@ class GstCherryPicker: if e.returncode == 1: retry = True continue - elif e.returncode == 3: - sys.exit(3) - except: + elif e.returncode == 2: + if revert_operation: + self.git(*revert_operation, can_fail=True) + raise + except Exception as e: # Result of subshell does not really matter pass @@ -217,4 +234,3 @@ def main(): if __name__ == '__main__': main() - |