Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """Hook to install the git config for using the clang-format merge driver.""" | |
| 6 | |
| 7 import os | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 _VERSION = 1 | |
| 12 | |
| 13 | |
| 14 def BuildGitCmd(*args): | |
| 15 cmd = [] | |
| 16 if sys.platform == 'win32': | |
| 17 cmd.append('git.bat') | |
|
Nico
2016/09/23 18:05:35
will this work on cygwin? (which seems like an arg
dcheng
2016/09/23 18:46:55
sys.platform == 'cygwin' on cygwin, so it's no pro
| |
| 18 else: | |
| 19 cmd.append('git') | |
| 20 cmd.extend(args) | |
| 21 return cmd | |
| 22 | |
| 23 | |
| 24 def main(): | |
| 25 # Assume that the script always lives somewhere inside the git repo. | |
| 26 os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
| 27 | |
| 28 try: | |
| 29 current_version = subprocess.check_output( | |
| 30 BuildGitCmd('config', 'merge.clang-format.version')) | |
| 31 try: | |
| 32 if int(current_version) >= _VERSION: | |
| 33 return | |
| 34 except ValueError: | |
| 35 # Not parseable for whatever reason: reinstall the config. | |
| 36 pass | |
| 37 except subprocess.CalledProcessError: | |
| 38 # git returned a non-zero return code, the config probably doesn't exist. | |
| 39 pass | |
| 40 | |
| 41 print 'Installing clang-format merge driver into .git/config...' | |
| 42 | |
| 43 subprocess.check_call( | |
| 44 BuildGitCmd('config', 'merge.clang-format.name', | |
| 45 'clang-format merge driver')) | |
| 46 subprocess.check_call( | |
| 47 BuildGitCmd('config', 'merge.clang-format.driver', | |
| 48 'clang_format_merge_driver %O %A %B %P')) | |
| 49 subprocess.check_call( | |
| 50 BuildGitCmd('config', 'merge.clang-format.recursive', 'binary')) | |
| 51 subprocess.check_call( | |
| 52 BuildGitCmd('config', 'merge.clang-format.version', str(_VERSION))) | |
| 53 | |
| 54 | |
| 55 if __name__ == '__main__': | |
| 56 sys.exit(main()) | |
| OLD | NEW |