Flutter Engine
The Flutter Engine
git_revision.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Get the Git HEAD revision of a specified Git repository."""
8
9import sys
10import subprocess
11import os
12import argparse
13
14
16 os_id = sys.platform
17 return os_id.startswith('win32') or os_id.startswith('cygwin')
18
19
20def get_repository_version(repository):
21 'Returns the Git HEAD for the supplied repository path as a string.'
22 if not os.path.exists(repository):
23 raise IOError('path does not exist')
24
25 git = 'git'
26 if is_windows():
27 git = 'git.bat'
28 version = subprocess.check_output([
29 git,
30 '-C',
31 repository,
32 'rev-parse',
33 'HEAD',
34 ])
35
36 return str(version.strip(), 'utf-8')
37
38
39def main():
40 parser = argparse.ArgumentParser()
41
42 parser.add_argument(
43 '--repository', action='store', help='Path to the Git repository.', required=True
44 )
45
46 args = parser.parse_args()
47 repository = os.path.abspath(args.repository)
48 version = get_repository_version(repository)
49 print(version.strip())
50
51 return 0
52
53
54if __name__ == '__main__':
55 sys.exit(main())
def get_repository_version(repository)
Definition: git_revision.py:20
def is_windows()
Definition: git_revision.py:15
Definition: main.py:1
def print(*args, **kwargs)
Definition: run_tests.py:49