From 0724c35c2886a9e85400f383b0663208fb24b6fa Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Fri, 10 Jul 2020 22:49:06 +0200 Subject: Fixup pre-commit hook to work with worktrees For git worktree setups, the hooks sit with the original repo (usually the initial clone). Worktrees with older version checkouts then miss the blacklist->excludelist rename, and consequently fail. Change-Id: I5f60fabc7d5856c74d93c4ada54f57574e0fd1a9 --- .git-hooks/pre-commit | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to '.git-hooks') diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index 27fba7e487a3..c7d51a1bcb2e 100755 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -134,9 +134,15 @@ sub check_style($) my ($h) = @_; my $src = ClangFormat::get_extension_regex(); my @bad_names = (); - my $excluded_list_names = ClangFormat::get_excludelist(); my $clang_format = ClangFormat::find(); + ## Check if ClangFormat has get_excludelist or the old + ## get_blacklist + my $excluded_list_names; + eval { ClangFormat::get_excludelist() }; + if ($@) { $excluded_list_names = ClangFormat::get_blacklist(); } + else { $excluded_list_names = ClangFormat::get_excludelist(); } + # Get a list of non-deleted changed files. open (FILES, "git diff-index --cached --diff-filter=AM --name-only $h |") || die "Cannot run git diff."; while (my $filename = ) -- cgit