blob: a133a48c22aebcbdfbc8e5233046c5e689ef0862 [file] [log] [blame]
Alexandre Ramesb78f1392016-07-01 14:22:22 +01001# Copyright 2014, VIXL authors
armvixlad96eda2013-06-14 11:42:37 +01002# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# * Redistributions of source code must retain the above copyright notice,
8# this list of conditions and the following disclaimer.
9# * Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12# * Neither the name of ARM Limited nor the names of its contributors may be
13# used to endorse or promote products derived from this software without
14# specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND ANY
17# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19# DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT,
20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27import re
28import util
29import os.path
Jacob Bramleye52f29d2018-08-15 11:07:51 +010030from pipes import quote
armvixlad96eda2013-06-14 11:42:37 +010031
armvixldb644342015-07-21 11:37:10 +010032def is_git_repository_root(path):
Jacob Bramleye52f29d2018-08-15 11:07:51 +010033 command = 'git -C ' + quote(path) + ' rev-parse --show-toplevel'
34 status, toplevel = util.getstatusoutput(command)
35 if status != 0: return False
36 return os.path.samefile(toplevel, path)
armvixlad96eda2013-06-14 11:42:37 +010037
armvixlad96eda2013-06-14 11:42:37 +010038def get_tracked_files():
armvixl330dc712014-11-25 10:38:32 +000039 command = 'git ls-tree HEAD -r --full-tree --name-only'
armvixlad96eda2013-06-14 11:42:37 +010040
armvixl330dc712014-11-25 10:38:32 +000041 status, tracked = util.getstatusoutput(command)
armvixlad96eda2013-06-14 11:42:37 +010042 if status != 0: util.abort('Failed to list tracked files.')
43
44 return tracked
45
46
47# Get untracked files in src/, test/, and tools/.
48def get_untracked_files():
49 status, output = util.getstatusoutput('git status -s')
50 if status != 0: util.abort('Failed to get git status.')
51
52 untracked_regexp = re.compile('\?\?.*(src/|test/|tools/).*(.cc$|.h$)')
53 files_in_watched_folder = lambda n: untracked_regexp.search(n) != None
54 untracked_files = filter(files_in_watched_folder, output.split('\n'))
55
56 return untracked_files