# Path: git_common.py
# def run(*cmd, **kwargs):
#   """The same as run_with_stderr, except it only returns stdout."""
#   return run_with_stderr(*cmd, **kwargs)[0]
# 
# def root():
#   return config('depot-tools.upstream', 'origin/master')
# 
# def set_config(option, value, scope='local'):
#   run('config', '--' + scope, option, value)
# 
# def get_or_create_merge_base(branch, parent=None):
#   """Finds the configured merge base for branch.
# 
#   If parent is supplied, it's used instead of calling upstream(branch).
#   """
#   base = branch_config(branch, 'base')
#   base_upstream = branch_config(branch, 'base-upstream')
#   parent = parent or upstream(branch)
#   if not parent:
#     return None
#   actual_merge_base = run('merge-base', parent, branch)
# 
#   if base_upstream != parent:
#     base = None
#     base_upstream = None
# 
#   def is_ancestor(a, b):
#     return run_with_retcode('merge-base', '--is-ancestor', a, b) == 0
# 
#   if base:
#     if not is_ancestor(base, branch):
#       logging.debug('Found WRONG pre-set merge-base for %s: %s', branch, base)
#       base = None
#     elif is_ancestor(base, actual_merge_base):
#       logging.debug('Found OLD pre-set merge-base for %s: %s', branch, base)
#       base = None
#     else:
#       logging.debug('Found pre-set merge-base for %s: %s', branch, base)
# 
#   if not base:
#     base = actual_merge_base
#     manual_merge_base(branch, base, parent)
# 
#   return base
# 
# def tags(*args):
#   return run('tag', *args).splitlines()
# 
# Path: git_common.py
# def hash_one(reflike):
#   return run('rev-parse', reflike)


import argparse
import sys
import subprocess2
from git_common import run, root, set_config, get_or_create_merge_base, tags
from git_common import hash_one
#!/usr/bin/env python
# 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.





def main(args):
  parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter
  )
  parser.add_argument('branch_name')
  g = parser.add_mutually_exclusive_group()
  g.add_argument('--upstream_current', action='store_true',
                 help='set upstream branch to current branch.')
  g.add_argument('--upstream', metavar='REF', default=root(),
                 help='upstream branch (or tag) to track.')
  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)

  try:
    if opts.upstream_current:
      run('checkout', '--track', '-b', opts.branch_name)
    else:

# Path: git_common.py
# def run(*cmd, **kwargs):
#   """The same as run_with_stderr, except it only returns stdout."""
#   return run_with_stderr(*cmd, **kwargs)[0]
# 
# def root():
#   return config('depot-tools.upstream', 'origin/master')
# 
# def set_config(option, value, scope='local'):
#   run('config', '--' + scope, option, value)
# 
# def get_or_create_merge_base(branch, parent=None):
#   """Finds the configured merge base for branch.
# 
#   If parent is supplied, it's used instead of calling upstream(branch).
#   """
#   base = branch_config(branch, 'base')
#   base_upstream = branch_config(branch, 'base-upstream')
#   parent = parent or upstream(branch)
#   if not parent:
#     return None
#   actual_merge_base = run('merge-base', parent, branch)
# 
#   if base_upstream != parent:
#     base = None
#     base_upstream = None
# 
#   def is_ancestor(a, b):
#     return run_with_retcode('merge-base', '--is-ancestor', a, b) == 0
# 
#   if base:
#     if not is_ancestor(base, branch):
#       logging.debug('Found WRONG pre-set merge-base for %s: %s', branch, base)
#       base = None
#     elif is_ancestor(base, actual_merge_base):
#       logging.debug('Found OLD pre-set merge-base for %s: %s', branch, base)
#       base = None
#     else:
#       logging.debug('Found pre-set merge-base for %s: %s', branch, base)
# 
#   if not base:
#     base = actual_merge_base
#     manual_merge_base(branch, base, parent)
# 
#   return base
# 
# def tags(*args):
#   return run('tag', *args).splitlines()
# 
# Path: git_common.py
# def hash_one(reflike):
#   return run('rev-parse', reflike)


# Path: git_new_branch.py
import argparse
import sys
import subprocess2
from git_common import run, root, set_config, get_or_create_merge_base, tags
from git_common import hash_one

#!/usr/bin/env python
# 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.





def main(args):
  parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter
  )
  parser.add_argument('branch_name')
  g = parser.add_mutually_exclusive_group()
  g.add_argument('--upstream_current', action='store_true',
                 help='set upstream branch to current branch.')
  g.add_argument('--upstream', metavar='REF', default=root(),
                 help='upstream branch (or tag) to track.')
  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)

  try:
    if opts.upstream_current:
      run('checkout', '--track', '-b', opts.branch_name)
    else:

      if opts.upstream in tags():