Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: scripts/slave/git_setup.py

Issue 15270004: Add step generator protocol, remove annotated_checkout, remove script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Checkout blobs do not need to be generators Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """This script ensures that a given directory is an initialized git repo."""
6
7 import argparse
8 import logging
9 import os
10 import subprocess
11 import sys
12
13
14 def run_git(*args, **kwargs):
15 """Runs git with given arguments.
16
17 kwargs are passed through to subprocess.
18
19 If the kwarg 'throw' is provided, this behaves as check_call, otherwise will
20 return git's return value.
21 """
22 logging.info('Running: git %s %s', args, kwargs)
23 func = subprocess.check_call if kwargs.pop('throw', True) else subprocess.call
24 return func(('git',)+args, **kwargs)
25
26
27 def main():
28 parser = argparse.ArgumentParser()
29 parser.add_argument('path', help='Path to prospective git repo.',
30 required=True)
31 parser.add_argument('url', help='URL of remote to make origin.',
32 required=True)
33 parser.add_argument('verbose', action='store_true')
34 opts = parser.parse_args()
35
36 path = opts.path
37 url = opts.url
38
39 logging.getLogger().setLevel(logging.DEBUG if opts.verbose else logging.WARN)
40
41 if not os.path.exists(path):
42 os.makedirs(path)
43
44 exists = run_git('branch', cwd=path, throw=False) == 0
45 if exists:
46 run_git('remote', 'rm', 'origin', cwd=path)
Mike Stip (use stip instead) 2013/05/18 00:37:22 may want to make this an option in case release sc
iannucci 2013/05/18 04:00:36 Yeah I thought of that, but for now it's all origi
47 else:
48 run_git('init', cwd=path)
49 run_git('remote', 'add', 'origin', url, cwd=path)
50 return 0
51
52
53 if __name__ == '__main__':
54 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698