Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / solenv / clang-format / check-last-commit
blob2db666ab2aec023b9e225e4e851adb90d57ef43d
1 #!/usr/bin/env perl
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.
10 use strict;
11 use warnings;
12 use lib "solenv/clang-format";
13 use ClangFormat;
15 sub check_style()
17 if ( ! -e ".git" )
19 # Can't diff when this is not a git checkout.
20 return;
23 my $src = ClangFormat::get_extension_regex();
24 my @good_names = ();
25 my @bad_names = ();
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
32 # copies.
33 open (FILES, "git diff-tree -r --diff-filter=AM --name-only HEAD^ HEAD |") || die "Cannot run git diff.";
34 while (my $filename = <FILES>)
36 chomp $filename;
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");
46 exit(1);
48 if (ClangFormat::check_style($clang_format, $filename))
50 push @good_names, $filename;
52 else
54 push @bad_names, $filename;
59 # Enforce style.
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");
68 exit(1);
70 else
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");
78 check_style();
80 exit(0);
82 # vim: set shiftwidth=4 softtabstop=4 expandtab: