OLD | NEW |
(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']) |
OLD | NEW |