forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_revision.py
executable file
·48 lines (38 loc) · 1.14 KB
/
git_revision.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Get the Git HEAD revision of a specified Git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import subprocess
import os
import argparse
def GetRepositoryVersion(repository):
"Returns the Git HEAD for the supplied repository path as a string."
if not os.path.exists(repository):
raise IOError("path doesn't exist")
version = subprocess.check_output([
'git',
'-C',
repository,
'rev-parse',
'HEAD',
])
return version.strip()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--repository',
action='store',
help='Path to the Git repository.',
required=True)
args = parser.parse_args()
repository = os.path.abspath(args.repository)
version = GetRepositoryVersion(repository)
print(version.strip())
return 0
if __name__ == '__main__':
sys.exit(main())