commit: ddc366ebdee7d36d092e2346c58a04ffb59098ae
parent b3c11efaa27c0b13386b36ea2b56b742c99c7e4b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 14 Oct 2025 18:40:48 +0200
post-update.reuse: Give non-compliance summary
Diffstat:
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/git-hooks/post-update.reuse b/git-hooks/post-update.reuse
@@ -1,22 +1,41 @@
#!/usr/bin/env perl
+# reuse lint appropriate for git-hook (short summary, no output on success)
# SPDX-FileCopyrightText: 2025 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: BSD-3-Clause
use JSON;
use Cwd;
+use builtin qw(reftype);
+use strict;
my $base = getcwd;
+if ($base =~ /\.git$/) {
+ $base =~ s/\.git$/\.work/;
+ chdir $base or die "chdir failed: $!";
+}
-chdir $base =~ s/\.git$/\.work/ if $base =~ /\.git$/;
-
-open(my $reuse_out, '-|', 'reuse lint -j') or die "Failed to execute reuse: $!";
+open(FH, '-|', 'reuse lint -j') or die "Failed to execute reuse: $!";
undef $/; # slurp
-my $reuse_json = decode_json(<$reuse_out>);
-close($reuse_out);
+my $reuse_json = decode_json(<FH>);
+# ignore reuse exit status
+if (not close(FH) and $!) {
+ die "Error closing reuse pipe: $!"
+}
+
+if ($reuse_json->{"summary"}->{"compliant"} != JSON::true) {
+ my $obj = $reuse_json->{"non_compliant"};
+ foreach my $key (keys %{$obj}) {
+ my $v = $obj->{$key};
+ my $ref_type = reftype($v);
-my $summary = $reuse_json->{"summary"};
-if($summary->{"compliant"} != JSON::true) {
- print "reuse: files_total: ", $summary->{"files_total"}, "\n";
- print "reuse: files_with_copyright_info: ", $summary->{"files_with_copyright_info"}, "\n";
- print "reuse: files_with_licensing_info: ", $summary->{"files_with_licensing_info"}, "\n";
+ if ($ref_type eq 'ARRAY') {
+ my $n = scalar @{$v};
+ print "reuse: ", $key, ": @ " , $n, " items\n" if $n > 0;
+ } elsif ($ref_type eq 'HASH') {
+ my $n = scalar keys %{$v};
+ print "reuse: ", $key, ": # " , $n, " items\n" if $n > 0;
+ } else {
+ print "reuse: ", $key, ": [", $ref_type ,"] " , $v, "\n";
+ }
+ }
}