Files
chromium_depot_tools/git_new_branch.py
Mike Frysinger 124bb8e53c switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.

Reformatted using:
files=( $(
	git ls-tree -r --name-only HEAD | \
		grep -Ev -e '^(third_party|recipes)/' | \
		grep '\.py$';
	git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"

The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py

These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py

Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2023-09-06 05:48:55 +00:00

91 lines
3.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Create new branch tracking origin HEAD by default.
"""
import argparse
import sys
import git_common
import subprocess2
def create_new_branch(branch_name,
upstream_current=False,
upstream=None,
inject_current=False):
upstream = upstream or git_common.root()
try:
if inject_current:
below = git_common.current_branch()
if below is None:
raise Exception('no current branch')
above = git_common.upstream(below)
if above is None:
raise Exception('branch %s has no upstream' % (below))
git_common.run('checkout', '--track', above, '-b', branch_name)
git_common.run('branch', '--set-upstream-to', branch_name, below)
elif upstream_current:
git_common.run('checkout', '--track', '-b', branch_name)
else:
if upstream in git_common.tags():
# TODO(iannucci): ensure that basis_ref is an ancestor of HEAD?
git_common.run('checkout', '--no-track', '-b', branch_name,
git_common.hash_one(upstream))
git_common.set_config('branch.%s.remote' % branch_name, '.')
git_common.set_config('branch.%s.merge' % branch_name, upstream)
else:
# TODO(iannucci): Detect unclean workdir then stash+pop if we
# need to teleport to a conflicting portion of history?
git_common.run('checkout', '--track', upstream, '-b',
branch_name)
git_common.get_or_create_merge_base(branch_name)
except subprocess2.CalledProcessError as cpe:
sys.stdout.write(cpe.stdout.decode('utf-8', 'replace'))
sys.stderr.write(cpe.stderr.decode('utf-8', 'replace'))
return 1
sys.stderr.write('Switched to branch %s.\n' % branch_name)
return 0
def main(args):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description=__doc__,
)
parser.add_argument('branch_name')
g = parser.add_mutually_exclusive_group()
g.add_argument('--upstream-current',
'--upstream_current',
action='store_true',
help='set upstream branch to current branch.')
g.add_argument('--upstream',
metavar='REF',
help='upstream branch (or tag) to track.')
g.add_argument('--inject-current',
'--inject_current',
action='store_true',
help='new branch adopts current branch\'s upstream,' +
' and new branch becomes current branch\'s upstream.')
g.add_argument('--lkgr',
action='store_const',
const='lkgr',
dest='upstream',
help='set basis ref for new branch to lkgr.')
opts = parser.parse_args(args)
return create_new_branch(opts.branch_name, opts.upstream_current,
opts.upstream, opts.inject_current)
if __name__ == '__main__': # pragma: no cover
try:
sys.exit(main(sys.argv[1:]))
except KeyboardInterrupt:
sys.stderr.write('interrupted\n')
sys.exit(1)