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

Unified Diff: gclient_scm.py

Issue 242140: Git support in presubmit tests.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_scm.py
===================================================================
--- gclient_scm.py (revision 27963)
+++ gclient_scm.py (working copy)
@@ -23,6 +23,7 @@
import gclient_utils
SVN_COMMAND = "svn"
+GIT_COMMAND = "git"
### SCM abstraction layer
@@ -437,6 +438,62 @@
# -----------------------------------------------------------------------------
+# Git utils:
+
+
+def CaptureGit(args, in_directory=None, print_error=True):
+ """Runs git, capturing output sent to stdout as a string.
+
+ Args:
+ args: A sequence of command line parameters to be passed to git.
+ in_directory: The directory where git is to be run.
+
+ Returns:
+ The output sent to stdout as a string.
+ """
+ c = [GIT_COMMAND]
+ c.extend(args)
+
+ # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for
+ # the git.exe executable, but shell=True makes subprocess on Linux fail
+ # when it's called with a list because it only tries to execute the
+ # first string ("git").
+ stderr = None
+ if not print_error:
+ stderr = subprocess.PIPE
+ return subprocess.Popen(c,
+ cwd=in_directory,
+ shell=sys.platform.startswith('win'),
+ stdout=subprocess.PIPE,
+ stderr=stderr).communicate()[0]
+
+
+def CaptureGitStatus(files):
+ """Returns git status.
+
+ @files can be a string (one file) or a list of files.
+
+ Returns an array of (status, file) tuples."""
+ command = ["diff", "--name-status", "-r", "origin.."]
+ if not files:
+ pass
+ elif isinstance(files, basestring):
+ command.append(files)
+ else:
+ command.extend(files)
+
+ status = CaptureGit(command).rstrip()
+ results = []
+ if status:
+ for statusline in status.split('\n'):
+ m = re.match('^(\w)\t(.+)$', statusline)
+ if not m:
+ raise Exception("status currently unsupported: %s" % statusline)
+ results.append(('%s ' % m.group(1), m.group(2)))
+ return results
+
+
+# -----------------------------------------------------------------------------
# SVN utils:
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698