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

Unified Diff: py/utils/git_utils.py

Issue 341193004: Add lots of utils, PRESUBMIT.py (Closed) Base URL: https://skia.googlesource.com/common.git@master
Patch Set: Address comments Created 6 years, 6 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 | « py/utils/android_utils.py ('k') | py/utils/misc.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: py/utils/git_utils.py
diff --git a/py/utils/git_utils.py b/py/utils/git_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..da7f0976ef2dc07852fd506a11d5bc9c9d6085c7
--- /dev/null
+++ b/py/utils/git_utils.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# Copyright (c) 2014 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 module contains functions for using git."""
+
+
+import os
+import shell_utils
+
+
+GIT = 'git.bat' if os.name == 'nt' else 'git'
+
+
+def Add(addition):
+ """Run 'git add <addition>'"""
+ shell_utils.run([GIT, 'add', addition])
+
+def AIsAncestorOfB(a, b):
+ """Return true if a is an ancestor of b."""
+ return shell_utils.run([GIT, 'merge-base', a, b]).rstrip() == FullHash(a)
+
+def FullHash(commit):
+ """Return full hash of specified commit."""
+ return shell_utils.run([GIT, 'rev-parse', '--verify', commit]).rstrip()
+
+def IsMerge(commit):
+ """Return True if the commit is a merge, False otherwise."""
+ rev_parse = shell_utils.run([GIT, 'rev-parse', commit, '--max-count=1',
+ '--no-merges'])
+ last_non_merge = rev_parse.split('\n')[0]
+ # Get full hash since that is what was returned by rev-parse.
+ return FullHash(commit) != last_non_merge
+
+def MergeAbort():
+ """Abort in process merge."""
+ shell_utils.run([GIT, 'merge', '--abort'])
+
+def ShortHash(commit):
+ """Return short hash of the specified commit."""
+ return shell_utils.run([GIT, 'show', commit, '--format=%h', '-s']).rstrip()
+
+def GetRemoteMasterHash(git_url):
+ return shell_utils.run([GIT, 'ls-remote', git_url, '--verify',
+ 'refs/heads/master'])
« no previous file with comments | « py/utils/android_utils.py ('k') | py/utils/misc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698