lib/App/gh/Command/Pull.pm

filter: Statementstmt 30.1% 16 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 26.2% 21 / 80 CC 10 SCAR 42.4
CC
10
Cov
23%
run
110.0
options
2.0
BEGIN
1.0
CRAP 69.2
« lib/App/gh/Utils.pm ↑ Summary lib/App/gh/Command/Pullreq/Send.pm »
1 package App::gh::Command::Pull;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 App::gh::Command::Pull - pull changes from other forks.
11  
12 =head1 USAGE
13  
14 First you show up all fork network:
15  
16 $ gh network
17  
18 Then you can pull changes from one:
19  
20 $ gh pull [id] (from branch) (to branch)
21  
22 For example:
23  
24 $ gh pull gugod
25  
26 This will create a gugod-master branch:
27  
28 =head1 OPTIONS
29  
30 --branch
31  
32 create tracked branch for fork.
33  
34 --merge
35  
36 merge changes from fork.
37  
38 =head3 Github Steps:
39  
40 Step 1: Check out a new branch to test the changes — run this from your project directory
41  
42 git checkout -b chocolateboy-optional_dep_and_warnings_fixes master
43  
44 Step 2: Bring in chocolateboy's changes and test
45  
46 git pull http://github.com/chocolateboy/App-gh.git optional_dep_and_warnings_fixes
47  
48 Step 3: Merge the changes and update the server
49  
50 git checkout master
51 git merge chocolateboy-optional_dep_and_warnings_fixes
52 git push origin master
53  
54 =cut
55  
56 0 ▶sub options { (
Subroutine options: not called CC=1 SCAR=6.9
Pod undocumented
57 0 "m|merge" => "merge",
58 "b|branch" => "branch",
59 "verbose" => "verbose",
60 "ssh" => "protocol_ssh", # git@github.com:c9s/repo.git
61 "http" => "protocol_http", # http://github.com/c9s/repo.git
62 "https" => "protocol_https", # https://github.com/c9s/repo.git
63 "git|ro" => "protocol_git" # git://github.com/c9s/repo.git
64 ) }
65  
66 0 ▶sub run {
Subroutine run: not called CC=10 SCAR=47.0
Pod undocumented
67 0 my ( $self, $acc, $from_branch, $to_branch ) = @_;
68  
69 0 ▶ unless ( $acc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($acc) 0 0 0
70 0 print "Usage: \n";
71 0 print " gh pull [userid] (from branch) (to branch)\n\n";
72  
73  
74  
75 0 my $origin_url = qx( git remote -v | grep origin | grep fetch );
76 0 my ($userid,$repo) = ($origin_url =~ m{:(\w+)/(.*?)\.git$});
77  
78 0 print "Available forks:\n";
79  
80 # XXX: refactor this ... XD
81 0 my $objs = App::gh->api->request(GET => qq(repos/show/$userid/$repo/network));
82 0 my $networks = $objs->{network};
83 0 for my $net ( @$networks ) {
84 print sprintf( "% 20s - watchers(%d) forks(%d)\n"
85 , $net->{owner} . '/' . $net->{name}
86 , $net->{watchers}
87 , $net->{forks}
88 0 );
89 }
90 0 print "\n";
91 0 return;
92 }
93  
94 0 ▶ $from_branch ||= 'master';
Condition0%0/2
$from_branch ||= "master"
l!l
00
MC/DC0%0/1
$from_branch ||= "master"
$from_branch
Truth table0%0/2
A
A= $from_branch
Aresult
11
00
95 0 ▶ $to_branch ||= 'master';
Condition0%0/2
$to_branch ||= "master"
l!l
00
MC/DC0%0/1
$to_branch ||= "master"
$to_branch
Truth table0%0/2
A
A= $to_branch
Aresult
11
00
96  
97 0 ▶ if( qx(git diff) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (`git diff`) 0 0 0
98 0 die "Your repository is dirty!\n";
99 }
100  
101 0 ▶ die "git config not found." if ! -e ".git/config" ;
Branch: 1 branch
BranchTrueFalseTotal
unless -e ".git/config" 0 0 0
102  
103 0 my $remote_name = $acc;
104 0 my $fork_branch_name = "$acc-$from_branch";
105 0 my $current_repo = $self->get_current_repo();
106 0 my $fork_uri = $self->gen_uri( $acc , $current_repo );
107  
108 0 ▶ unless( qx(git remote | grep $remote_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (`git remote | grep $remote_name `) 0 0 0
109 0 print "Adding remote [$remote_name] for [$fork_uri]\n";
110 0 qx(git remote add $remote_name $fork_uri);
111 }
112  
113 0 print "Fetching $acc ...\n";
114 0 print qx(git fetch $acc);
115  
116  
117 0 ▶ if( $self->{merge} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"merge"}) 0 0 0
118 0 print "Checking out $to_branch ...\n";
119 0 qx(git checkout $to_branch);
120  
121 0 print "Merging changes from [$acc/$from_branch] to $to_branch\n";
122 0 print qx(git merge $acc/$from_branch);
123 }
124  
125 0 ▶ if( $self->{branch} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"branch"}) 0 0 0
126 0 print "Creating track branch for $acc/$from_branch\n";
127 0 print qx(git checkout --track -b $fork_branch_name $acc/$from_branch);
128 }
129  
130 0 print "Done\n";
131 }
132  
133 1 1;
« lib/App/gh/Utils.pm ↑ Summary lib/App/gh/Command/Pullreq/Send.pm »