2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # Checks the style of the files changed in the last commit, for CI purposes.
12 use lib
"solenv/clang-format";
19 # Can't diff when this is not a git checkout.
23 my $src = ClangFormat
::get_extension_regex
();
26 my $blacklist_names = ClangFormat
::get_blacklist
();
27 my $clang_format = ClangFormat
::find
();
29 # Get a list of non-deleted changed files.
30 # Explicitly use the low-level 'git diff-tree' (rather than plain 'git
31 # diff') so we get the new, but not the old files for renames and/or
33 open (FILES
, "git diff-tree -r --diff-filter=AM --name-only HEAD^ HEAD |") || die "Cannot run git diff.";
34 while (my $filename = <FILES
>)
37 if ($filename =~ /\.($src)$/ and !exists($blacklist_names->{$filename}))
39 if (! -x
$clang_format)
41 my $version = ClangFormat
::get_wanted_version
();
43 print("solenv/clang-format/check-last-commit: ");
44 print("ERROR: no clang-format ${version} was found.\n\n");
48 if (ClangFormat
::check_style
($clang_format, $filename))
50 push @good_names, $filename;
54 push @bad_names, $filename;
60 if (scalar @bad_names)
62 print("\nERROR: The above differences were found between the code to commit \n");
63 print("and the clang-format rules. Tips:\n");
64 print("\n- You may run '/opt/lo/bin/clang-format -i <problematic file>' to fix up style automatically.\n");
65 print("- See solenv/clang-format/README on where to get the required version of clang-format binaries.\n");
66 print("- If you renamed a blacklisted file, update solenv/clang-format/blacklist accordingly to keep it blacklisted.\n");
67 print("\nsolenv/clang-format/check-last-commit: KO\n");
72 print("solenv/clang-format/check-last-commit: checked the following files:\n");
73 print(join("\n", @good_names));
74 print("\nsolenv/clang-format/check-last-commit: OK\n");
82 # vim: set shiftwidth=4 softtabstop=4 expandtab: