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() - diff --git a/subprojects/gst-docs/markdown/frequently-asked-questions/mono-repository.md b/subprojects/gst-docs/markdown/frequently-asked-questions/mono-repository.md index f8745ed9fc..4ee9120248 100644 --- a/subprojects/gst-docs/markdown/frequently-asked-questions/mono-repository.md +++ b/subprojects/gst-docs/markdown/frequently-asked-questions/mono-repository.md @@ -66,6 +66,8 @@ GITLAB_API_TOKEN=zytXYboB5yi3uggRpBM6 ./scripts/move_mrs_to_monorepo.py Don't worry - the script will prompt you for input along the way before it does anything. + + ### Must I use the script? Can't I just open a new MR? The script will move existing discussions and comments. This is particularly useful for MRs that have been reviewed already and have open discussion items. This makes sure we don't accidentally merge something even though there were outstanding issues, which we wouldn't know if you just filed a new MR and closed the old Merge Request. @@ -84,7 +86,11 @@ You can do this via the GitLab user interface by editing the issue and then chan We provide a [scripts/rebase-branch-from-old-module.py](https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/scripts/rebase-branch-from-old-module.py) script in the `gstreamer` repository that you should use to rebase branches from the old GStreamer module repositories onto the main `gstreamer` repository. -This script will only modify your local gstreamer mono repository checkout and not upload anything to GitLab or create any Merge Requests of course. You don't even need a GitLab account to run it. +This script will only modify your local gstreamer mono repository checkout and not upload anything to GitLab or create any Merge Requests of course. You don't even need a GitLab account to run it. You can use the script as following: + +``` +./scripts/rebase-branch-from-old-module.py https://gitlab.freedesktop.org/user/gst-plugins-bad my_wip_dev_branch +``` ## I use or distribute the release tarballs - how will this affect me?