| 1 | package ShipIt::VC::Git; | ||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use base 'ShipIt::VC'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use File::Temp (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 0 | ▶ | sub command { 'git' } | ||||||||||||
|
Subroutine
command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 9 | 0 | my ($class, $conf) = @_; | |||||||||||||
| 10 | 0 | my $self = bless {}, $class; | |||||||||||||
| 11 | 0 | $self->{tagpattern} = $conf->value( $self->command . ".tagpattern" ); | |||||||||||||
| 12 | 0 | $self->{sign_tag} = $conf->value( $self->command . ".sign_tag" ); | |||||||||||||
| 13 | 0 | $self->{push_to} = $conf->value( $self->command . ".push_to" ); | |||||||||||||
| 14 | 0 | return $self; | |||||||||||||
| 15 | } | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 NAME | ||||||||||||||
| 18 | |||||||||||||||
| 19 | ShipIt::VC::Git -- ShipIt's git support | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =head1 CONFIGURATION | ||||||||||||||
| 22 | |||||||||||||||
| 23 | In your .shipit configuration file, the following options are recognized: | ||||||||||||||
| 24 | |||||||||||||||
| 25 | =over | ||||||||||||||
| 26 | |||||||||||||||
| 27 | =item B<git.tagpattern> | ||||||||||||||
| 28 | |||||||||||||||
| 29 | Defines how the tag are defined in your git repo. | ||||||||||||||
| 30 | |||||||||||||||
| 31 | =item B<git.sign_tag> | ||||||||||||||
| 32 | |||||||||||||||
| 33 | This should be set to a truthy value, if you wish the tags to be GPG signed. | ||||||||||||||
| 34 | (C<git tag -s ...>) | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =item B<git.push_to> | ||||||||||||||
| 37 | |||||||||||||||
| 38 | If you want the newly created to be pushed elsewhere (for instance in your | ||||||||||||||
| 39 | public git repository), then you can specify the destination in this variable | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =back | ||||||||||||||
| 42 | |||||||||||||||
| 43 | =cut | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | sub exists_tagged_version { | ||||||||||||
|
Subroutine
exists_tagged_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 46 | 0 | my ($self, $ver) = @_; | |||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | my $command = $self->command; | |||||||||||||
| 49 | 0 | my $x = `git tag -l $ver`; | |||||||||||||
| 50 | 0 | chomp $x; | |||||||||||||
| 51 | 0 | return $x; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | sub commit { | ||||||||||||
|
Subroutine
commit: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 55 | 0 | my ($self, $msg) = @_; | |||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | my $command = $self->command; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | if ( my $unk = `git ls-files -z --others --exclude-standard` ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | $unk =~ s/\0/\n/g; | |||||||||||||
| 61 | 0 | die "Unknown local files:\n$unk\n\nUpdate .gitignore, or $command add them"; | |||||||||||||
| 62 | 0 | exit(1); | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | # commit | ||||||||||||||
| 66 | 0 | my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg'); | |||||||||||||
| 67 | 0 | print $tmp_fh $msg; | |||||||||||||
| 68 | 0 | my $tmp_fn = "$tmp_fh"; | |||||||||||||
| 69 | 0 | system($command, "commit", "-a", "-F", $tmp_fn); | |||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | ▶ | if (my $where = $self->{push_to}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 0 | my $branch = $self->_get_branch; | |||||||||||||
| 73 | 0 | ▶ | if ($branch) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | warn "pushing to $where"; | |||||||||||||
| 75 | 0 | system($self->command, "push", $where, $branch); | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | ▶ | sub _get_branch { | ||||||||||||
|
Subroutine
_get_branch: not called CC=1 SCAR=6.9
| |||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | open my $fh, '<', '.git/HEAD'; | |||||||||||||
| 84 | 0 | chomp(my $head = do { local $/; <$fh> }); | |||||||||||||
| 85 | 0 | close $fh; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | my ($branch) = $head =~ m!ref: refs/heads/(\S+)!; | |||||||||||||
| 88 | 0 | return $branch; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | ▶ | sub local_diff { | ||||||||||||
|
Subroutine
local_diff: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 92 | 0 | my ($self, $file) = @_; | |||||||||||||
| 93 | 0 | my $command = $self->command; | |||||||||||||
| 94 | 0 | return `$command diff --no-color HEAD $file`; | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 0 | ▶ | sub _tag_of_version { | ||||||||||||
|
Subroutine
_tag_of_version: not called CC=3 SCAR=24.8
| |||||||||||||||
| 98 | 0 | my ($self, $ver) = @_; | |||||||||||||
| 99 | 0 | ▶ | my $tag = $self->{tagpattern} || ''; | ||||||||||||
|
Condition0%0/2
$self->{'tagpattern'} || ''
MC/DC0%0/1
$self->{'tagpattern'} || ''
$self->{'tagpattern'}
Truth table0%0/2
A
A= $self->{'tagpattern'}
| |||||||||||||||
| 100 | 0 | ▶ | $tag .= "%v" unless $tag =~ /\%v/i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 101 | 0 | $tag =~ s/\%v/$ver/ig; | |||||||||||||
| 102 | 0 | return $tag; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 0 | ▶ | sub tag_version { | ||||||||||||
|
Subroutine
tag_version: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 106 | 0 | my ($self, $ver, $msg) = @_; | |||||||||||||
| 107 | 0 | ▶ | $msg ||= "Tagging version $ver.\n"; | ||||||||||||
|
Condition0%0/2
$msg ||= "Tagging version $ver.\n"
MC/DC0%0/1
$msg ||= "Tagging version $ver.\n"
$msg
Truth table0%0/2
A
A= $msg
| |||||||||||||||
| 108 | 0 | my $tmp_fh = File::Temp->new(UNLINK => 1, SUFFIX => '.msg'); | |||||||||||||
| 109 | 0 | print $tmp_fh $msg; | |||||||||||||
| 110 | 0 | my $tmp_fn = "$tmp_fh"; | |||||||||||||
| 111 | 0 | my $tag = $self->_tag_of_version($ver); | |||||||||||||
| 112 | 0 | ▶ | system($self->command, "tag", "-a", ($self->{sign_tag} ? "-s" : ()), "-F", $tmp_fn, $tag) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 113 | and die "Tagging of version '$ver' failed.\n"; | ||||||||||||||
| 114 | |||||||||||||||
| 115 | 0 | ▶ | if (my $where = $self->{push_to}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | 0 | warn "pushing to $where"; | |||||||||||||
| 117 | 0 | system($self->command, "push", $where, tag => $tag); | |||||||||||||
| 118 | } | ||||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 0 | ▶ | sub are_local_diffs { | ||||||||||||
|
Subroutine
are_local_diffs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 122 | 0 | my ($self, $ver) = @_; | |||||||||||||
| 123 | 0 | my $command = $self->command; | |||||||||||||
| 124 | 0 | my $diff = `$command diff --no-color $ver`; | |||||||||||||
| 125 | 0 | ▶ | return $diff =~ /\S/ ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | } | ||||||||||||||
| 127 | |||||||||||||||
| 128 | 2 | 1; | |||||||||||||