Add --description option to branch
[stgit] / contrib / stg-sink
CommitLineData
cefdc327
YD
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5sub _run {
03c8cd3a 6 #print(' >> ', @_, "\n");# and 0;
cefdc327
YD
7 system(@_);
8}
9
10my $dopush=1;
11my $pop='pop -a';
12while (@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
24if (@ARGV == 0) {
25 $ARGV[0] = `stg top`;
26}
27
28my @oldapplied=`stg applied`;
29chomp (@oldapplied);
30
31_run('stg '.$pop) &&
32 die "cannot pop all patches";
33_run('stg push ' . join (' ', @ARGV)) &&
34 die "error pushing patches";
35
36if ($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}