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 | |
| 12 _VERSION = 1 | |
| 13 | |
| 14 def main(): | |
| 15 # Assume that the script always lives somewhere inside the git repo. | |
| 16 os.chdir(os.path.dirname(os.path.abspath(__file__))) | |
| 17 | |
| 18 try: | |
| 19 current_version = subprocess.check_output( | |
| 20 ['git', 'config', 'merge.clang-format.version']) | |
| 21 try: | |
| 22 if int(current_version) >= _VERSION: | |
| 23 print 'Skipping...' | |
|
Nico
2016/09/22 13:22:37
this is probably fast enough that we could just un
dcheng
2016/09/22 17:08:53
Oops, I meant to remove this print anyway.
| |
| 24 return | |
| 25 except ValueError: | |
| 26 # Not parseable for whatever reason: reinstall the config. | |
| 27 pass | |
| 28 except subprocess.CalledProcessError: | |
| 29 # git returned a non-zero return code, the config probably doesn't exist. | |
| 30 pass | |
| 31 | |
| 32 print 'Installing clang-format merge driver into .git/config...' | |
| 33 | |
| 34 subprocess.check_call( | |
| 35 ['git', 'config', 'merge.clang-format.name', 'clang-format merge driver']) | |
|
Nico
2016/09/22 13:22:37
Is the cwd for running hooks guaranteed? Does this
dcheng
2016/09/22 17:08:53
That's why there's an os.chdir on line 16 =)
| |
| 36 subprocess.check_call(['git', 'config', 'merge.clang-format.driver', | |
| 37 'clang_format_merge_driver %O %A %B %P']) | |
| 38 subprocess.check_call( | |
| 39 ['git', 'config', 'merge.clang-format.recursive', 'binary']) | |
| 40 subprocess.check_call( | |
| 41 ['git', 'config', 'merge.clang-format.version', str(_VERSION)]) | |
| 42 | |
| 43 | |
| 44 if __name__ == '__main__': | |
| 45 sys.exit(main()) | |
| OLD | NEW |