2 # dgit repos policy hook script for Debian
5 # dgit-repos-policy-debian DISTRO DGIT-REPOS-DIR ACTION...
7 # dgit-repos-policy-debian ... check-list
8 # dgit-repos-policy-debian ... check-package PACKAGE
9 # dgit-repos-policy-debian ... push PACKAGE \
10 # VERSION SUITE TAGNAME DELIBERATELIES [...]
12 # exit status is bitmap; bit weights (values) as follows
13 # 1 failure; operation must be rejected; other bits will be ignored
14 # 2 suppress dgit-repos-server's ff check ("push" only)
15 # 4 blow away repo away right away (ie before push or fetch)
16 # ("check-package" only)
18 # cwd for push is a temporary repo where the to-be-pushed objects have
19 # been received; TAGNAME is the version-based tag
21 # policy hook for a particular package will be invoked only once at
30 our $distro = shift @ARGV // die "need DISTRO";
31 our $repos = shift @ARGV // die "need DGIT-REPOS-DIR";
32 our $action = shift @ARGV // die "need ACTION";
33 our $pkg = shift @ARGV;
35 # We assume that it is not possible for NEW to have a version older
38 # Whenever pushing, we check for
39 # source-package-local tainted history
40 # global tainted history
41 # can be overridden by --deliberately except for an admin prohib taint
43 # ALL of the following apply only if history is secret:
45 # if NEW has no version, or a version which is not in our history[1]
48 # if any suite's version is in our history[1], publish our history
49 # otherwise discard our history,
50 # tainting --deliberately-include-questionable-history
52 # if NEW has a version which is in our history[1]
54 # require explicit specification of one of
55 # --deliberately-include-questionable-history
56 # --deliberately-not-fast-forward
57 # (latter will taint old NEW version --d-i-q-h)
61 # [1] looking for the relevant git tag for the version number and not
62 # caring what that tag refers to.
67 $!=0; $?=0; my $json = `dgit -d $distro archive-api-query $subpath`;
68 defined $json or die "$subpath $! $?";
69 return decode_json $json;
72 sub new_has_vsn_in_our_history () {
73 my $in_new = apiquery "/dsc_in_suite/new/$pkg";
74 foreach my $entry (@$in_new) {
75 my $vsn = $entry->{version};
76 die "$pkg ?" unless defined $vsn;
77 my $tag = debiantag $vsn;
78 $?=0; my $r = system qw(git show-ref --verify --quiet), $tag;
81 die "$pkg tag $tag $? $!";
86 sub selectpackage () {
88 die if $pkg =~ m#[^-+.0-9a-z]#;
90 if (!chdir "$repos/$pkg") {
91 die "$pkg $!" unless $!==ENOENT;
95 if (~(stat _)[2] & 05) {
109 my $fn = ${*::}{"action_$cmd"};
110 $fn or die "unknown ACTION";