Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Unified Diff: tools/clang_format_merge_driver/install_git_hook.py

Issue 2359933005: DEPS hook for installing the clang-format merge driver. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang_format_merge_driver/OWNERS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
« no previous file with comments | « tools/clang_format_merge_driver/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698