Sha256: 42b7a12fc31df4192c417c7cb5204c7b297f0917fdfe6f988de55e6322b00703

Contents?: true

Size: 1.84 KB

Versions: 19

Compression:

Stored size: 1.84 KB

Contents

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

"""This script ensures that a given directory is an initialized git repo."""

import argparse
import logging
import os
import subprocess
import sys


def run_git(git_cmd, *args, **kwargs):
  """Runs git with given arguments.

  kwargs are passed through to subprocess.

  If the kwarg 'throw' is provided, this behaves as check_call, otherwise will
  return git's return value.
  """
  logging.info('Running: %s %s %s', git_cmd, args, kwargs)
  func = subprocess.check_call if kwargs.pop('throw', True) else subprocess.call
  return func((git_cmd,)+args, **kwargs)


def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--path', help='Path to prospective git repo.',
                      required=True)
  parser.add_argument('--url', help='URL of remote to make origin.',
                      required=True)
  parser.add_argument('--git_cmd_path',
                      help='Path to the git command to run.',
                      default='git')
  parser.add_argument('--remote', help='Name of the git remote.',
                      default='origin')
  parser.add_argument('-v', '--verbose', action='store_true')
  opts = parser.parse_args()

  path = opts.path
  remote = opts.remote
  url = opts.url

  logging.getLogger().setLevel(logging.DEBUG if opts.verbose else logging.WARN)

  if not os.path.exists(path):
    os.makedirs(path)

  if os.path.exists(os.path.join(path, '.git')):
    run_git(opts.git_cmd_path, 'config', '--remove-section',
            'remote.%s' % remote, cwd=path)
  else:
    run_git(opts.git_cmd_path, 'init', cwd=path)
  run_git(opts.git_cmd_path, 'remote', 'add', remote, url, cwd=path)
  return 0


if __name__ == '__main__':
  sys.exit(main())

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
libv8-5.7.492.65.1 vendor/depot_tools/recipes/recipe_modules/git/resources/git_setup.py
libv8-5.7.492.65.0 vendor/depot_tools/recipes/recipe_modules/git/resources/git_setup.py
libv8-5.7.492.65.0beta1 vendor/depot_tools/recipes/recipe_modules/git/resources/git_setup.py
libv8-5.6.326.50.0beta1 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.5 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.4 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.3 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.2 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.1 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.0 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.3.332.38.0beta2 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.2.361.43.1 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.2.361.43.0 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.1.281.59.1 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.1.281.59.0 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.1.281.59.0beta3 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.0.71.48.3 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.0.71.48.2 vendor/depot_tools/recipe_modules/git/resources/git_setup.py
libv8-5.0.71.48.0beta2 vendor/depot_tools/recipe_modules/git/resources/git_setup.py