File Coverage

blib/lib/ShipIt/VC/Mercurial.pm
Criterion Covered Total %
statement 9 38 23.6
branch 0 8 0.0
condition 0 3 0.0
subroutine 3 10 30.0
pod 5 7 71.4
total 17 66 25.7


line stmt bran cond sub pod time code
1             package ShipIt::VC::Mercurial;
2 2     2   12 use strict;
  2         4  
  2         83  
3 2     2   10 use base 'ShipIt::VC';
  2         14  
  2         180  
4 2     2   11 use File::Temp ();
  2         4  
  2         1077  
5              
6 0     0 0   sub command { 'hg' }
7              
8             sub new {
9 0     0 0   my ($class, $conf) = @_;
10 0           my $self = bless {}, $class;
11 0           $self->{push_to} = $conf->value( $self->command . ".push_to" );
12 0           return $self;
13             }
14              
15             =head1 NAME
16              
17             ShipIt::VC::Mercurial -- ShipIt's Mercurial support
18              
19             =head1 CONFIGURATION
20              
21             In your .shipit configuration file, the following options are recognized:
22              
23             =over
24              
25             =item B
26              
27             If you want the newly created to be pushed elsewhere (for instance in your
28             public Mercurial repository), then you can specify the destination in this variable
29              
30             =back
31              
32             =cut
33              
34             sub exists_tagged_version {
35 0     0 1   my ($self, $ver) = @_;
36              
37 0           my $command = $self->command;
38 0           my $x = `$command tags`;
39 0           return $x =~ m/^$ver\s/m;
40             }
41              
42             sub commit {
43 0     0 1   my ($self, $msg) = @_;
44              
45 0           my $command = $self->command;
46              
47 0 0         if ( my $unk = `$command status -u` ) {
48 0           die "Unknown local files:\n$unk\n\nUpdate .hgignore, or $command add them";
49 0           exit(1);
50             }
51              
52             # commit
53 0           system($command, "commit", "-m", $msg);
54             }
55              
56             sub local_diff {
57 0     0 1   my ($self, $file) = @_;
58 0           my $command = $self->command;
59 0           return `$command diff $file`;
60             }
61              
62             sub tag_version {
63 0     0 1   my ($self, $ver, $msg) = @_;
64 0   0       $msg ||= "Tagging version $ver.\n";
65              
66 0           warn "TAG: $msg, $ver";
67              
68 0 0         system($self->command, "tag", "-m", $msg, $ver)
69             and die "Tagging of version '$ver' failed.\n";
70              
71 0 0         if (my $where = $self->{push_to}) {
72 0           warn "pushing to $where";
73 0           system($self->command, "push", $where);
74             }
75             }
76              
77             sub are_local_diffs {
78 0     0 1   my ($self) = @_;
79 0           my $command = $self->command;
80 0           my $diff = `$command status`;
81 0 0         return $diff =~ /\S/ ? 1 : 0;
82             }
83              
84             1;