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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « py/utils/android_utils.py ('k') | py/utils/misc.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """This module contains functions for using git."""
7
8
9 import os
10 import shell_utils
11
12
13 GIT = 'git.bat' if os.name == 'nt' else 'git'
14
15
16 def Add(addition):
17 """Run 'git add <addition>'"""
18 shell_utils.run([GIT, 'add', addition])
19
20 def AIsAncestorOfB(a, b):
21 """Return true if a is an ancestor of b."""
22 return shell_utils.run([GIT, 'merge-base', a, b]).rstrip() == FullHash(a)
23
24 def FullHash(commit):
25 """Return full hash of specified commit."""
26 return shell_utils.run([GIT, 'rev-parse', '--verify', commit]).rstrip()
27
28 def IsMerge(commit):
29 """Return True if the commit is a merge, False otherwise."""
30 rev_parse = shell_utils.run([GIT, 'rev-parse', commit, '--max-count=1',
31 '--no-merges'])
32 last_non_merge = rev_parse.split('\n')[0]
33 # Get full hash since that is what was returned by rev-parse.
34 return FullHash(commit) != last_non_merge
35
36 def MergeAbort():
37 """Abort in process merge."""
38 shell_utils.run([GIT, 'merge', '--abort'])
39
40 def ShortHash(commit):
41 """Return short hash of the specified commit."""
42 return shell_utils.run([GIT, 'show', commit, '--format=%h', '-s']).rstrip()
43
44 def GetRemoteMasterHash(git_url):
45 return shell_utils.run([GIT, 'ls-remote', git_url, '--verify',
46 'refs/heads/master'])
OLDNEW
« 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