Index: tools/clang_format_merge_driver/install_git_hook.py |
diff --git a/tools/clang_format_merge_driver/install_git_hook.py b/tools/clang_format_merge_driver/install_git_hook.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..d20744d631470c0fb7c9165828591c9bc115c917 |
--- /dev/null |
+++ b/tools/clang_format_merge_driver/install_git_hook.py |
@@ -0,0 +1,45 @@ |
+#!/usr/bin/env python |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+"""Hook to install the git config for using the clang-format merge driver.""" |
+ |
+import os |
+import subprocess |
+import sys |
+ |
+ |
+_VERSION = 1 |
+ |
+def main(): |
+ # Assume that the script always lives somewhere inside the git repo. |
+ os.chdir(os.path.dirname(os.path.abspath(__file__))) |
+ |
+ try: |
+ current_version = subprocess.check_output( |
+ ['git', 'config', 'merge.clang-format.version']) |
+ try: |
+ if int(current_version) >= _VERSION: |
+ 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.
|
+ return |
+ except ValueError: |
+ # Not parseable for whatever reason: reinstall the config. |
+ pass |
+ except subprocess.CalledProcessError: |
+ # git returned a non-zero return code, the config probably doesn't exist. |
+ pass |
+ |
+ print 'Installing clang-format merge driver into .git/config...' |
+ |
+ subprocess.check_call( |
+ ['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 =)
|
+ subprocess.check_call(['git', 'config', 'merge.clang-format.driver', |
+ 'clang_format_merge_driver %O %A %B %P']) |
+ subprocess.check_call( |
+ ['git', 'config', 'merge.clang-format.recursive', 'binary']) |
+ subprocess.check_call( |
+ ['git', 'config', 'merge.clang-format.version', str(_VERSION)]) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |