diff --git a/bin/get_formulas.py b/bin/get_formulas.py index dba2e4b..3b795e0 100755 --- a/bin/get_formulas.py +++ b/bin/get_formulas.py @@ -155,6 +155,13 @@ def push(REMOTES, DEST): fetch_remote(repo.remotes[remote], formula) +def checkout_remote_and_branch(REMOTE_BRANCH, DEST): + for formula in FORMULAS.keys(): + FULL_PATH = '%s/%s-formula' % (DEST, formula) + branch = REMOTE_BRANCH.split('/')[1] + git(['checkout', '-qB', branch, REMOTE_BRANCH], cwd=FULL_PATH) + + with open('FORMULAS.yaml', 'r') as f: FORMULAS = yaml.load(f) @@ -179,6 +186,7 @@ Examples: -r mycompany_forks no_prefixes git@gitlab.mycompany.com: saltstack-formulas''') parser.add_argument('-u', '--update', nargs='*', help='Switch to origin/master and git pull. Optionally it can accept a list of remotes as arguments, that will be fetched.') parser.add_argument('-p', '--push', nargs='+', help='Pushes (with --force) to the given list of remotes from origin/master to their master and production branch, and then fetches them.') +parser.add_argument('--checkout', nargs=1, help='Checkout to the specified remote/branch.') parser.add_argument('--use-pygit2', action='store_true', help='Use pygit2 instead of invoking git whenever possible.') args = parser.parse_args() @@ -193,7 +201,7 @@ if args.remove_symlinks: remove_symlinks() # Every option below requires the --destination argument to be set -if args.clone or args.symlink or args.clone_from or args.clone_branch or args.add_remote or args.update or args.push: +if args.clone or args.symlink or args.clone_from or args.clone_branch or args.add_remote or args.update or args.push or args.checkout: will_run = True if (args.clone_from or args.clone_branch) and not args.clone: @@ -231,6 +239,9 @@ if args.clone or args.symlink or args.clone_from or args.clone_branch or args.ad if args.push: push(args.push, args.destination[0]) + if args.checkout: + checkout_remote_and_branch(args.checkout[0], args.destination[0]) + if not will_run: parser.print_help() sys.exit(1)