forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
38 lines (30 loc) · 953 Bytes
/
pre-commit
File metadata and controls
38 lines (30 loc) · 953 Bytes
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
#!/usr/bin/env {{ python }}
import os
import subprocess
import sys
LOCATION = r'{{ location }}'
SCRIPTS = os.path.dirname(os.path.dirname(LOCATION))
def files(staged=True):
try:
lines = []
for line in subprocess.check_output(
['git', 'diff', '--name-only'] + (['--staged'] if staged else []),
encoding='utf-8',
).splitlines():
if line:
lines.append(line)
return lines
except subprocess.CalledProcessError:
return []
staged = files(staged=True)
unstaged = files(staged=False)
project_files = []
for line in staged or unstaged:
if line.endswith('pbxproj'):
project_files.append(line)
if project_files:
code = subprocess.run(['perl', os.path.join(SCRIPTS, 'sort-Xcode-project-file')] + project_files).returncode
if staged:
code += subprocess.run(['git', 'add'] + project_files).returncode
sys.exit(code)
sys.exit(0)