bump product version to 6.3.0.0.beta1
[LibreOffice.git] / solenv / clang-format / check-last-commit
blob57939815bb0ae4aef009b6ecf0757b1a5445a06c
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 my $commit = 0;
16 my $commit_id = 'HEAD';
18 sub check_style()
20 if ( ! -e ".git" )
22 # Can't diff when this is not a git checkout.
23 return;
26 my $src = ClangFormat::get_extension_regex();
27 my @good_names = ();
28 my @bad_names = ();
29 my $blacklist_names = ClangFormat::get_blacklist();
30 my $clang_format = ClangFormat::find();
31 my $parent = $commit + 1;
33 # Get a list of non-deleted changed files.
34 # Explicitly use the low-level 'git diff-tree' (rather than plain 'git
35 # diff') so we get the new, but not the old files for renames and/or
36 # copies.
37 open (FILES, "git diff-tree -r --diff-filter=AM --name-only ${commit_id}~${parent} ${commit_id}~${commit} |") || die "Cannot run git diff.";
38 while (my $filename = <FILES>)
40 chomp $filename;
41 if ($filename =~ /\.($src)$/ and !exists($blacklist_names->{$filename}))
43 if (! -x $clang_format)
45 my $version = ClangFormat::get_wanted_version();
47 print("solenv/clang-format/check-last-commit: ");
48 print("ERROR: no clang-format ${version} was found.\n\n");
50 exit(1);
52 if (ClangFormat::check_style($clang_format, $filename))
54 push @good_names, $filename;
56 else
58 push @bad_names, $filename;
63 # Enforce style.
64 if (scalar @bad_names)
66 print("\nERROR: The above differences were found between the code to commit \n");
67 print("and the clang-format rules. Tips:\n");
68 print("\n- You may run '/opt/lo/bin/clang-format -i <problematic file>' to fix up style automatically.\n");
69 print("- See solenv/clang-format/README on where to get the required version of clang-format binaries.\n");
70 print("- If you renamed a blacklisted file, update solenv/clang-format/blacklist accordingly to keep it blacklisted.\n");
71 print("\nsolenv/clang-format/check-last-commit: KO\n");
72 exit(1);
74 else
76 print("solenv/clang-format/check-last-commit: checked the following files:\n");
77 print(join("\n", @good_names));
78 print("\nsolenv/clang-format/check-last-commit: OK\n");
82 if (scalar(@ARGV) == 1)
84 if (($ARGV[0] !~ /^[0-9]+$/) || (scalar($ARGV[0]) >= 8))
86 $commit_id = $ARGV[0];
88 else
90 $commit = $ARGV[0];
94 check_style();
96 exit(0);
98 # vim: set shiftwidth=4 softtabstop=4 expandtab: