diff options
author | Diana Picus <diana.picus@linaro.org> | 2017-06-09 19:14:08 +0200 |
---|---|---|
committer | Diana Picus <diana.picus@linaro.org> | 2017-07-07 18:08:56 +0200 |
commit | efc7bdaf3f4e53b0b9c15c4b1100dcf2e9d30b09 (patch) | |
tree | 50ab59c5106a23a2f11ee9478407f278afc520b4 /scripts | |
parent | 3601bea50533d4ba06fafac16664183cdb250ab0 (diff) | |
download | linaro-scripts-efc7bdaf3f4e53b0b9c15c4b1100dcf2e9d30b09.tar.gz |
[llvmpush] Add llvm push
Add support for pushing the current branch in all linked subprojects in
a given config. If they are not on the same branch, an error is thrown.
The branches are pushed as linaro-local/$user/$branch, where $branch is
the local name of the branch and $user is the user as seen in
LLVM_GITUSER (we might want to change to a more intelligent way to get
the user in the future).
We achieve this by adding a new method to LLVMSourceConfig:
for_each_enabled, which takes an action and applies it to all the
enabled subprojects. If an exception is thrown by the action, it is
rethrown by the action as a RuntimeError specifying which project the
action was being applied to. Note that this does not behave like a
transaction - the action may have been applied to some of the projects
already, and there's no way to undo it. It's also a bit difficult to
tell which projects the action was applied on (in the future we should
probably log that info).
We also provide an action that simply pushes the current branch to
origin with the updated name. This makes sure the remote branch will
live in an isolated namespace where it won't conflict with other
people's branches.
We also update some of the internals of LLVMSourceConfig to throw
exceptions if some of the subprojects that are linked are not worktrees
on the same branch as LLVM. In the past they were just ignored, but that
doesn't seem like a sane default anymore.
Change-Id: I9c917658d65b5d0e7bad3310efce07a0fe5bce5e
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/llvm.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/scripts/llvm.py b/scripts/llvm.py index 829c720..2252ab2 100644 --- a/scripts/llvm.py +++ b/scripts/llvm.py @@ -3,11 +3,12 @@ import os from sys import exit -from modules.llvm import LLVMSubproject, LLVMSourceConfig +from modules.llvm import LLVMSubproject, LLVMSourceConfig, push_current_branch from linaropy.git.clone import Clone from linaropy.proj import Proj from argparse import Action, ArgumentParser, RawTextHelpFormatter +from functools import partial def die(message, config_to_dump=None): @@ -64,6 +65,22 @@ def projects(args): dump_config(config) + +def push_branch(args): + """Push current branch to origin.""" + + proj = Proj() + + llvm_worktree_root = get_worktree_root(args.env) + config = LLVMSourceConfig(proj, llvm_worktree_root) + + llvmBranch = Clone(proj, llvm_worktree_root).getbranch() + + try: + config.for_each_enabled(partial(push_current_branch, proj)) + except RuntimeError as exc: + die("Failed to push branch because: " + str(exc) + str(exc.__cause__)) + ########################################################################## # Command line parsing # ########################################################################## @@ -106,5 +123,11 @@ projs.add_argument( metavar='subproject', help="Unlink given subprojects.") +# Subcommand for pushing the current branch to origin +push = subcommands.add_parser( + "push", + help="Push current branch to origin linaro-local/<user>/<branch>, for all linked subprojects.") +push.set_defaults(run_command=push_branch) + args = options.parse_args() args.run_command(args) |