lib/App/gh/Command/Update.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 40.3% 21 / 52 CC 7 SCAR 35.0
CC
7
Cov
36%
run
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 33.1
« lib/App/gh/Config.pm ↑ Summary lib/App/gh/Command/Clone.pm »
1 package App::gh::Command::Update;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(App::gh::Command);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::gh;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use App::gh::Utils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 info
8 error
9 build_git_remote_command
10 git_current_branch
11 1 );
12  
13 =head1 NAME
14  
15 App::gh::Command::Update - remote update --prune
16  
17 =head1 DESCRIPTION
18  
19 Simply run git remote update --prune , git pull --all , then push back to
20 writable remotes.
21  
22 =cut
23  
24 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod undocumented
25 0 my $self = shift;
26 0 my @remotes = @_;
27  
28 0 ▶ unless ( -d ".git" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d ".git") 0 0 0
29 0 die "Not a repository";
30 }
31  
32 0 info "Running remote update with prune";
33 0 my @cmds = build_git_remote_command('update',{ prune => 1 });
34 0 ▶ system(@cmds) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(@cmds) == 0 or die error("system @cmds failed: $?") 0 0 0
35 or die error "system @cmds failed: $?";
36  
37 0 my $diff = qx(git diff);
38 0 chomp($diff);
39 0 ▶ die error("Can not update, you have uncommitted changes.") if $diff;
Branch: 1 branch
BranchTrueFalseTotal
if $diff 0 0 0
40  
41 0 my $current_head = git_current_branch;
42 0 ▶ if( @remotes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@remotes) { } 0 0 0
43 0 for my $remote (@remotes) {
44 0 info "Pull and rebase from $remote/$current_head...";
45 0 qx{git pull --rebase $remote $current_head};
46 }
47 }
48 else {
49 0 my @lines = split /\n/,qx{ git remote -v | grep '(fetch)'};
50 0 for my $line ( @lines ) {
51 0 my ( $remote, $uri, $type) = ($line =~ m{^(\w+)\s+(\S+)\s+\((\w+)\)} );
52 0 info "Pull and rebase from $remote ...";
53 0 qx{git pull --rebase $remote $current_head};
54  
55 # if( $uri =~ /^git\@github\.com/ ) {
56 # info "Pushing changes to $remote : $uri";
57 # qx{ git push $remote };
58 # }
59 }
60 }
61 0 info "Done";
62 }
63  
64 1 1;
« lib/App/gh/Config.pm ↑ Summary lib/App/gh/Command/Clone.pm »