New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
pre-commit-verify-branch-owner in vendors/sbin – NEMO

source: vendors/sbin/pre-commit-verify-branch-owner @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 2.7 KB
Line 
1#!/usr/bin/perl
2# ------------------------------------------------------------------------------
3# (C) British Crown Copyright 2006-17 Met Office.
4#
5# This file is part of FCM, tools for managing and building source code.
6#
7# FCM is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# FCM is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with FCM. If not, see <http://www.gnu.org/licenses/>.
19# ------------------------------------------------------------------------------
20
21use strict;
22use warnings;
23
24use FindBin;
25use lib "$FindBin::Bin/../lib";
26use FCM::Admin::System qw{verify_users};
27use FCM::System::CM::SVN;
28use FCM::Util;
29
30our @IGNORES = qw{Config Rel Share};
31
32my $UTIL = $FCM::Admin::System::UTIL;
33my $CM_SYS = FCM::System::CM::SVN->new({'util' => $UTIL});
34
35if (!caller()) {
36    main(@ARGV);
37}
38
39sub main {
40    local(@ARGV) = @_;
41    my ($repos, $txn) = @ARGV;
42
43    my %layout_config = $CM_SYS->load_layout_config('file://' . $repos);
44    if (!$layout_config{'level-owner-branch'}) {
45        return;
46    }
47
48    # Get list of new paths
49    my %lines_of; # $lines_of{$owner} = [$path, ...]
50    LINE:
51    for my $line ($CM_SYS->stdout(qw{svnlook changed -t}, $txn, $repos)) {
52        my $status = substr($line, 0, 1);
53        if ($status eq 'A') {
54            my $path = substr($line, 4);
55            # $is_local=1
56            my $layout = $CM_SYS->get_layout_common($repos, $txn, $path, 1);
57            my $owner = $layout->get_branch_owner();
58            if ($owner && !grep {$_ eq $owner} @IGNORES) {
59                if (!exists($lines_of{$owner})) {
60                    $lines_of{$owner} = [];
61                }
62                push(@{$lines_of{$owner}}, $line);
63            }
64        }
65    }
66
67    # Verify branch owners, if necessary
68    my @bad_users = verify_users(keys(%lines_of));
69    for my $bad_user (@bad_users) {
70        for my $line (@{$lines_of{$bad_user}}) {
71            warn("[INVALID BRANCH OWNER] $line\n");
72        }
73    }
74    exit(scalar(@bad_users));
75}
76
771;
78__END__
79
80=head1 NAME
81
82pre-commit-verify-branch-owner
83
84=head1 SYNOPSIS
85
86    pre-commit-verify-branch-owner REPOS TXN
87
88=head1 ARGUMENTS
89
90Accept the same arguments as a Subversion pre-commit hook.
91
92=head1 DESCRIPTION
93
94This program ensures that users create a branch with its owner correctly set.
95
96=head1 COPYRIGHT
97
98E<169> Crown copyright Met Office. All rights reserved.
99
100=cut
Note: See TracBrowser for help on using the repository browser.