| File: | lib/App/TimeTracker/Command/Git.pm |
| Coverage: | 60.9% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package App::TimeTracker::Command::Git; | ||||||
| 2 | 2 2 2 | 1321 6 40 | use strict; | ||||
| 3 | 2 2 2 | 9 6 54 | use warnings; | ||||
| 4 | 2 2 2 2 2 2 | 80 92 26 32 5 22 | use 5.010; | ||||
| 5 | |||||||
| 6 | # ABSTRACT: TimeTracker Git plugin | ||||||
| 7 | |||||||
| 8 | 2 2 2 | 9 4 19 | use Moose::Role; | ||||
| 9 | 2 2 2 | 6547 11094 16 | use Git::Repository; | ||||
| 10 | |||||||
| 11 | has 'branch' => (is=>'rw',isa=>'Str'); | ||||||
| 12 | has 'merge' => (is=>'ro',isa=>'Bool'); | ||||||
| 13 | has 'nobranch' => (is=>'ro',isa=>'Bool'); | ||||||
| 14 | |||||||
| 15 | after 'cmd_start' => sub { | ||||||
| 16 | my $self = shift; | ||||||
| 17 | |||||||
| 18 | return unless $self->branch; | ||||||
| 19 | return if $self->nobranch; | ||||||
| 20 | |||||||
| 21 | my $r = Git::Repository->new( work_tree => '.' ); | ||||||
| 22 | my $branch = $self->branch; | ||||||
| 23 | my %branches = map { s/^\s+//; $_=>1 } $r->run('branch'); | ||||||
| 24 | |||||||
| 25 | if ($branches{'* '.$branch}) { | ||||||
| 26 | say "Already on branch $branch"; | ||||||
| 27 | return; | ||||||
| 28 | } | ||||||
| 29 | |||||||
| 30 | if (!$branches{$branch}) { | ||||||
| 31 | $r->command('branch',$branch); | ||||||
| 32 | } | ||||||
| 33 | |||||||
| 34 | print $r->command('checkout',$branch)->stderr->getlines; | ||||||
| 35 | }; | ||||||
| 36 | |||||||
| 37 | after cmd_stop => sub { | ||||||
| 38 | my $self = shift; | ||||||
| 39 | return unless $self->merge; | ||||||
| 40 | |||||||
| 41 | my $r = Git::Repository->new( work_tree => '.' ); | ||||||
| 42 | my $branch = $self->branch; | ||||||
| 43 | my %branches = map { s/^\s+//; $_=>1 } $r->run('branch'); | ||||||
| 44 | |||||||
| 45 | unless ($branches{'* '.$branch}) { | ||||||
| 46 | say "Not in branch $branch, won't merge."; | ||||||
| 47 | return; | ||||||
| 48 | } | ||||||
| 49 | my $tags = join(', ',map { $_->name } @{$self->tags}) || ''; | ||||||
| 50 | $r->command('checkout','master'); | ||||||
| 51 | $r->command("merge",$branch,"--no-ff",'-m',"implemented $branch $tags"); | ||||||
| 52 | }; | ||||||
| 53 | |||||||
| 54 | sub cmd_merge { | ||||||
| 55 | 0 | 0 | my $self = shift; | ||||
| 56 | |||||||
| 57 | 0 | my $r = Git::Repository->new( work_tree => '.' ); | |||||
| 58 | 0 | my $branch = $self->branch; | |||||
| 59 | 0 0 0 | my %branches = map { s/^\s+//; $_=>1 } $r->run('branch'); | |||||
| 60 | |||||||
| 61 | 0 | unless ($branches{'* '.$branch}) { | |||||
| 62 | 0 | say "Not in branch $branch, won't merge."; | |||||
| 63 | 0 | return; | |||||
| 64 | } | ||||||
| 65 | 0 | my $tags = join(', ',map { $_->name } @{$self->tags}) || ''; | |||||
| 66 | 0 | $r->command('checkout','master'); | |||||
| 67 | 0 | $r->command("merge",$branch,"--no-ff",'-m',"implemented $branch $tags"); | |||||
| 68 | |||||||
| 69 | } | ||||||
| 70 | |||||||
| 71 | 2 2 2 | 1617 6 28 | no Moose::Role; | ||||
| 72 | 1; | ||||||
| 73 | |||||||