chiark / gitweb /
Make use exception raised by removedirs.
[stgit] / contrib / stg-sink
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 sub _run {
6   print(' >> ', @_, "\n");# and 0;
7   system(@_);
8 }
9
10 my $dopush=1;
11 my $pop='pop -a';
12 while (@ARGV and $ARGV[0] =~ m/^-/) {
13   if ($ARGV[0] eq '-n') {
14     $dopush=0;
15     shift @ARGV;
16   }
17   if ($ARGV[0] eq '-t') {
18     shift @ARGV;
19     $pop = 'goto '.shift @ARGV;
20   }
21 }
22
23 # default: sink current patch
24 if (@ARGV == 0) {
25   $ARGV[0] = `stg top`;
26 }
27
28 my @oldapplied=`stg applied`;
29 chomp (@oldapplied);
30
31 _run('stg '.$pop) &&
32   die "cannot pop all patches";
33 _run('stg push ' . join (' ', @ARGV)) &&
34   die "error pushing patches";
35
36 if ($dopush) {
37   my @newapplied=`stg applied`;
38   chomp (@newapplied);
39   my @remaining=grep { my $check=$_;
40                        not grep { $check eq $_ } @newapplied;
41                      } @oldapplied;
42   _run('stg push ' . join (' ', @remaining)) &&
43     die "error pushing remaining patches";
44 }