2014-04-18 20:31:22 +02:00
|
|
|
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
# reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
# can be found in the LICENSE file
|
|
|
|
|
2014-04-18 20:31:22 +02:00
|
|
|
from exec_util import exec_cmd
|
|
|
|
import os
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-04-18 20:31:22 +02:00
|
|
|
def is_checkout(path):
|
|
|
|
""" Returns true if the path represents a git checkout. """
|
|
|
|
return os.path.exists(os.path.join(path, '.git'))
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-08-08 14:40:16 +02:00
|
|
|
def get_hash(path = '.', branch = 'HEAD'):
|
2014-04-18 20:31:22 +02:00
|
|
|
""" Returns the git hash for the specified branch/tag/hash. """
|
2015-03-17 00:34:35 +01:00
|
|
|
cmd = "git rev-parse %s" % branch
|
2014-04-18 20:31:22 +02:00
|
|
|
result = exec_cmd(cmd, path)
|
|
|
|
if result['out'] != '':
|
|
|
|
return result['out'].strip()
|
|
|
|
return 'Unknown'
|
|
|
|
|
|
|
|
def get_url(path = '.'):
|
|
|
|
""" Returns the origin url for the specified path. """
|
|
|
|
cmd = "git config --get remote.origin.url"
|
|
|
|
result = exec_cmd(cmd, path)
|
|
|
|
if result['out'] != '':
|
|
|
|
return result['out'].strip()
|
|
|
|
return 'Unknown'
|
|
|
|
|
2015-03-17 00:34:35 +01:00
|
|
|
def get_commit_number(path = '.', branch = 'HEAD'):
|
|
|
|
""" Returns the number of commits in the specified branch/tag/hash. """
|
|
|
|
cmd = "git rev-list --count %s" % branch
|
2014-04-18 20:31:22 +02:00
|
|
|
result = exec_cmd(cmd, path)
|
2015-03-17 00:34:35 +01:00
|
|
|
if result['out'] != '':
|
|
|
|
return result['out'].strip()
|
|
|
|
return '0'
|
2014-04-18 20:31:22 +02:00
|
|
|
|
|
|
|
def get_changed_files(path = '.'):
|
2012-04-03 03:34:16 +02:00
|
|
|
""" Retrieves the list of changed files. """
|
|
|
|
# not implemented
|
|
|
|
return []
|