Add a nickname configuration variable
[girocco.git] / toolbox / trash-project.pl
blobefe26d1c1831d2d68fa49a6cfa30dfd30fe60457
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;
12 sub mydie
14 print STDERR "@_\n";
15 exit(255);
18 undef(*CORE::GLOBAL::die);
19 *CORE::GLOBAL::die = \&mydie;
21 my $bin = '/srv/git-recyclebin';
23 my $project = shift @ARGV || die "Please give project name on command line.";
25 # WARNING!
26 # Physical removal isn't actually supported. You have to do it manually.
27 # This only deletes the project from the list.
28 my $delete = 0;
29 if ($project eq '--really-delete') {
30 $delete = 1;
31 $project = shift @ARGV || die "Please give project name on command line.";
34 # WARNING!
35 # Don't use this option while jobd is running. You run the risk of destroying data.
36 my $keep_forks = 0;
37 if ($project eq '--keep-forks') {
38 $keep_forks = 1;
39 $project = shift @ARGV || die "Please give project name on command line.";
42 my $p = Girocco::Project->load($project) || die "Project '$project' not found!";
44 if ($keep_forks) {
45 # Run GC on that repository so that objects don't get lost within forks
46 my $reporoot = $Girocco::Config::reporoot;
47 my $basedir = $Girocco::Config::basedir;
48 print "We have to run GC on the repo so that the forks don't lose data. Hang on...\n";
49 system("GIT_DIR=$reporoot/$project.git git config --unset gitweb.lastgc");
50 system("show_progress=1 $basedir/jobd/gc.sh $project");
51 } else {
52 die "Complicated situation: project still has forks. Please deal with it manually."
53 if (-d "$Girocco::Config::reporoot/$project/");
56 if (!$delete) {
57 die "Already have a deleted version of the project. You need to make a decision now."
58 if (-d "$bin/$project.git");
60 if ($project =~ m!/!) {
61 my $parent = $project; $parent =~ s{^(.+)/.*$}{$1};
62 system("mkdir -p '$bin/$parent'") == 0 || die "Problem creating directory hierarchy in recycle bin: $!";
65 rename $p->{'path'}, "$bin/$project.git" || die "Problem moving project data: $!";
67 $p->delete();
68 print "Project '$project' removed from repo.or.cz". ($delete ? '' : ", backup in $bin/$project.git") .".\n";