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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: scripts/slave/git_setup.py
diff --git a/scripts/slave/git_setup.py b/scripts/slave/git_setup.py
new file mode 100644
index 0000000000000000000000000000000000000000..b9cb0f0937c28759e195d29be1e5dcf4f691c62a
--- /dev/null
+++ b/scripts/slave/git_setup.py
@@ -0,0 +1,54 @@
+# Copyright (c) 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(*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: git %s %s', args, kwargs)
+ func = subprocess.check_call if kwargs.pop('throw', True) else subprocess.call
+ return func(('git',)+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('verbose', action='store_true')
+ opts = parser.parse_args()
+
+ path = opts.path
+ url = opts.url
+
+ logging.getLogger().setLevel(logging.DEBUG if opts.verbose else logging.WARN)
+
+ if not os.path.exists(path):
+ os.makedirs(path)
+
+ exists = run_git('branch', cwd=path, throw=False) == 0
+ if exists:
+ 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
+ else:
+ run_git('init', cwd=path)
+ run_git('remote', 'add', 'origin', url, cwd=path)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698