#!/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)