-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_utils.py
31 lines (24 loc) · 871 Bytes
/
git_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Utilities for working with git.
import os
import subprocess
# Returns the shortrev of HEAD of |repo_root|.
def GetRepoRevision(repo_root):
repo_rev_line = subprocess.Popen(
"git rev-parse --short HEAD",
shell=True,
stdout=subprocess.PIPE,
cwd=repo_root).stdout.read()
# Strip off the trailing newline.
return repo_rev_line.strip()
# Returns the commit date of HEAD of |repo_root|.
def GetRepoCommitDate(repo_root):
commit_date = subprocess.Popen(
"git show -s --date=short --format=%cd HEAD",
shell=True,
stdout=subprocess.PIPE,
cwd=repo_root).stdout.read()
# Strip off the trailing newline.
return commit_date.strip()
# Returns the shortrev of HEAD of the usage analyzer repo (i.e., this repo).
def GetUsageAnalyzerRepoRevision():
return GetRepoRevision(os.path.dirname(os.path.realpath(__file__)))