summaryrefslogtreecommitdiff
path: root/scripts/cros_enable_push.py
blob: f338289d55b43a11c0e69a1c2933f4fff4b50336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Script to setup push configuration in a git-repo checkout."""

import sys
from chromite.buildbot import configure_repo
from chromite.buildbot import repository
from chromite.lib import cros_build_lib


def _Usage(handle):
  print >>handle, (
     "Tool to fix git configuration and add push configuration to a repo.")
  print >>handle
  print >>handle, (
"""Fix git configuration, and enable git pushing to the remote.

To run this script, either invoke it from within a repo checkout, or pass it
the path of a repo checkout you'd like to configure.

Once that has been done, what would've been (for example):

git push ssh://gerrit.chromium.org:29418/chromiumos/chromite\
 HEAD:refs/for/master

Can now be done as:

git push cros HEAD:refs/for/master
""")

def main(argv):
  if len(argv) > 1:
    _Usage(sys.stderr)
    return 1
  if not argv:
    path = cros_build_lib.FindRepoCheckoutRoot()
    if path is None:
      _Usage(sys.stderr)
      print >>sys.stderr, "We're not in a repo checkout."
      return 1
  else:
    if argv[0] in ('-h', '--help', '--usage'):
      _Usage(sys.stderr)
      return 0
    path = argv[0]
    if not repository.IsARepoRoot(path):
      _Usage(sys.stderr)
      print >>sys.stderr, ("Path %s doesn't point to the root of a repository."
                           % (argv[0],))
      return 1

  print "Cleaning stale git configuration from %s" % (path,)
  configure_repo.FixBrokenExistingRepos(path)
  print "\nAdding git push configuration to %s" % (path,)
  configure_repo.FixExternalRepoPushUrls(path)