Commit 0b076919 authored by gregor herrmann's avatar gregor herrmann

New dpt subcommand: dpt-clean-mr-repos.

Script to remove local clones of packaging repositories which are gone from
salsa.debian.org.
parent 6ee57501
......@@ -94,6 +94,10 @@ See L<dpt-cd(1)>
See L<dpt-ci-failures(1)>.
=item B<clean-mr-repos> - remove local repos which are gone from salsa.debian.org
See L<dpt-clean-mr-repos(1)>.
=item B<checkout> - work on pkg-perl package
=item (also available as B<co>)
......
......@@ -180,6 +180,12 @@ Files: scripts/new-upstream
Copyright: 2018, gregor herrmann <gregoa@debian.org>
License: Artistic or GPL-1+
Files: scripts/clean-mr-repos
Copyright: 2017, Florian Schlichting <fsfs@debian.org>
2018, Damyan Ivanov <dmn@debian.org>
2018, gregor herrmann <gregoa@debian.org>
License: FIXME-fsfs
Files: lib/*
Copyright: 2016, Alex Muntada <alexm@alexm.org>
License: Artistic or GPL-1+
......
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use File::Path 'remove_tree';
use File::Spec 'catfile';
use Getopt::Long;
use feature 'say';
my ($help, $force);
GetOptions(
'help|h' => \$help,
'force|f' => \$force,
) or usage();
sub usage {
say "dpt-clean-mr-repos: find repos in packages/ not included in .mrconfig.packages";
say " --force: remove obsolete repos";
say " --help: this text";
exit !$help;
}
usage() if $help;
my $dpt_packages = $ENV{'DPT_PACKAGES'};
die "Required configuration variable DPT_PACKAGES is not set
in ~/.dpt.conf or ~/.config/dpt.conf or in your environment.\n" unless $dpt_packages;
$dpt_packages =~ s/~/$ENV{'HOME'}/;
die "No directory called '$dpt_packages' found: $!" unless -d $dpt_packages;
my $mrconfig = File::Spec->catfile("$dpt_packages", '..', '.mrconfig.packages');
die "Cannot find your $mrconfig, exiting.\nTry to run 'dpt salsa mrconfig'.\n" unless -e $mrconfig;
# read in known packages from .mrconfig.packages
my %cfg;
open my $fh, '<', $mrconfig;
while (<$fh>) {
next unless /^\[packages\/(.*)\]$/;
$cfg{$1} = 1;
}
close $fh;
# walk through packages/, identify extra ones
opendir (my $dh, $dpt_packages);
while (my $pkg = readdir $dh) {
# skip non-directories, like tarballs, build logs etc
next unless -d "$dpt_packages/$pkg";
# skip dotfiles
next if $pkg =~ /^\./;
unless ( -d "$dpt_packages/$pkg/.git" ) {
say "Skipping '$dpt_packages/$pkg' -- not a Git repository";
next;
}
if (!exists $cfg{$pkg}) {
if ($force) {
say "REMOVING $pkg";
remove_tree("$dpt_packages/$pkg");
} else {
say $pkg;
}
}
}
closedir $dh;
__END__
=head1 NAME
dpt-clean-mr-repos - remove local repos which are gone from salsa.debian.org
=head1 SYNOPSIS
B<dpt clean-mr-repos> I<[--force]> I<[--help]>
=head1 DESCRIPTION
B<dpt clean-mr-repos> checks which repos are locally in the I<DPT_PACKAGES>
directory that do no longer exist in F<.mrconfig.packages>, i.e. which are
no longer on salsa.debian.org in the group with active packages. The script
needs B<dpt salsa mrconfig> to be run beforehand as this creates
F<.mrconfig.packages>. Removal of obsolete repos happens only with
I<--force>.
=head1 OPTIONS
=over
=item B<--help>
Show this help.
=item B<--force>
Actually remove the local repositories. Without I<--force> they are just
listed.
=back
=head1 CONFIGURATION
B<dpt clean-mr-repos> uses the C<DPT_PACKAGES> environment variable.
See L<dpt-config(5)> for details.
=head1 COPYRIGHT AND LICENSE
Copyright 2017, Florian Schlichting <fsfs@debian.org>
2018, Damyan Ivanov <dmn@debian.org>
2018, gregor herrmann <gregoa@debian.org>
License: FIXME-fsfs
......@@ -99,6 +99,7 @@ pushrepo
removeuser
repack
repo
repos
repositoryname
retitle
rm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment