projects: consolidate and refactor project archive code
[girocco.git] / toolbox / trash-project.pl
blobb93134c80534cf3fec1df355ce432f9d66eaa7a0
1 #!/usr/bin/perl
3 # Send a project to the trash
5 use strict;
6 use warnings;
7 use lib @basedir@;
9 use Girocco::Config;
10 use Girocco::Project;
11 use Girocco::Util qw(noFatalsToBrowser);
12 BEGIN {noFatalsToBrowser}
14 my $project = shift @ARGV || die "Please give project name on command line.";
16 # WARNING!
17 # Physical removal isn't actually supported. You have to do it manually.
18 # This only deletes the project from the list.
19 my $delete = 0;
20 if ($project eq '--really-delete') {
21 $delete = 1;
22 $project = shift @ARGV || die "Please give project name on command line.";
25 # WARNING!
26 # Don't use this option while jobd is running. You run the risk of destroying data.
27 my $keep_forks = 0;
28 if ($project eq '--keep-forks') {
29 $keep_forks = 1;
30 $project = shift @ARGV || die "Please give project name on command line.";
33 my $p = Girocco::Project->load($project) || die "Project '$project' not found!";
35 if ($keep_forks) {
36 # Run GC on that repository so that objects don't get lost within forks
37 my $reporoot = $Girocco::Config::reporoot;
38 my $basedir = $Girocco::Config::basedir;
39 print "We have to run GC on the repo so that the forks don't lose data. Hang on...\n";
40 system($Girocco::Config::git_bin, "--git-dir=$reporoot/$project.git", 'config',
41 '--unset', 'gitweb.lastgc');
42 $ENV{'show_progress'} = 1;
43 system("$basedir/jobd/gc.sh", $project);
44 } else {
45 die "Complicated situation: project still has forks. Please deal with it manually."
46 if (-d "$Girocco::Config::reporoot/$project/");
49 my $archived = "";
50 if (!$delete) {
51 $archived = $p->archive_and_delete();
52 } else {
53 $p->delete();
55 print "Project '$project' removed from $Girocco::Config::name".
56 ($delete ? '' : ", backup in '$archived'") .".\n";