line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rex::SCM::Git; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
74
|
use v5.12.5; |
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
46
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
355
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
41
|
use Cwd qw(getcwd); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
363
|
|
9
|
2
|
|
|
2
|
|
36
|
use Rex::Commands::Fs; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
19
|
|
10
|
2
|
|
|
2
|
|
25
|
use File::Basename; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
172
|
|
11
|
2
|
|
|
2
|
|
20
|
use Rex::Helper::Run; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
118
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
26
|
use vars qw($CHECKOUT_BRANCH_COMMAND $CHECKOUT_TAG_COMMAND $CLONE_COMMAND); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1779
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$CLONE_COMMAND = "git clone %s %s %s"; |
16
|
|
|
|
|
|
|
$CHECKOUT_BRANCH_COMMAND = "git checkout -B %s origin/%s"; |
17
|
|
|
|
|
|
|
$CHECKOUT_TAG_COMMAND = "git checkout -B %s %s"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
2
|
|
|
2
|
0
|
7
|
my $that = shift; |
21
|
2
|
|
33
|
|
|
26
|
my $proto = ref($that) || $that; |
22
|
2
|
|
|
|
|
8
|
my $self = {@_}; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
6
|
bless( $self, $proto ); |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
10
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub checkout { |
30
|
2
|
|
|
2
|
0
|
10
|
my ( $self, $repo_info, $checkout_to, $checkout_opt ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
5
|
my %run_opt; |
33
|
2
|
50
|
|
|
|
7
|
$run_opt{env} = $checkout_opt->{env} if ( $checkout_opt->{env} ); |
34
|
2
|
50
|
|
|
|
5
|
my $clone_args = join( " ", @{ $checkout_opt->{clone_args} || [''] } ); |
|
2
|
|
|
|
|
32
|
|
35
|
|
|
|
|
|
|
|
36
|
2
|
50
|
|
|
|
35
|
if ( is_dir("$checkout_to/.git") ) { |
37
|
0
|
|
0
|
|
|
0
|
my $branch = $checkout_opt->{"branch"} || "master"; |
38
|
|
|
|
|
|
|
Rex::Logger::info( "Pulling " |
39
|
0
|
0
|
|
|
|
0
|
. $repo_info->{"url"} . " to " |
40
|
|
|
|
|
|
|
. ( $checkout_to ? $checkout_to : "." ) ); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
0
|
my $rebase = $checkout_opt->{"rebase"} ? '--rebase' : ''; |
43
|
0
|
|
|
|
|
0
|
my $out = i_run "git pull $rebase origin $branch", |
44
|
|
|
|
|
|
|
cwd => $checkout_to, |
45
|
|
|
|
|
|
|
fail_ok => 1, |
46
|
|
|
|
|
|
|
%run_opt; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
unless ( $? == 0 ) { |
49
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Error pulling.", "warn" ); |
50
|
0
|
|
|
|
|
0
|
Rex::Logger::info($out); |
51
|
0
|
|
|
|
|
0
|
die("Error pulling."); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
Rex::Logger::debug($out); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
if ( exists $checkout_opt->{"tag"} ) { |
58
|
0
|
|
|
|
|
0
|
my $tag = $checkout_opt->{tag}; |
59
|
0
|
|
|
|
|
0
|
my $checkout_cmd = sprintf( $CHECKOUT_TAG_COMMAND, $tag, $tag ); |
60
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Switching to tag " . $tag ); |
61
|
0
|
|
|
|
|
0
|
$out = i_run "git fetch origin", |
62
|
|
|
|
|
|
|
cwd => $checkout_to, |
63
|
|
|
|
|
|
|
fail_ok => 1, |
64
|
|
|
|
|
|
|
%run_opt; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
0
|
unless ( $? == 0 ) { |
67
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Error switching to tag.", "warn" ); |
68
|
0
|
|
|
|
|
0
|
Rex::Logger::info($out); |
69
|
0
|
|
|
|
|
0
|
die("Error switching to tag."); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
0
|
Rex::Logger::debug($out); |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
0
|
$out = i_run "$checkout_cmd", cwd => $checkout_to, fail_ok => 1, %run_opt; |
75
|
0
|
0
|
|
|
|
0
|
unless ( $? == 0 ) { |
76
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Error switching to tag.", "warn" ); |
77
|
0
|
|
|
|
|
0
|
Rex::Logger::info($out); |
78
|
0
|
|
|
|
|
0
|
die("Error switching to tag."); |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
0
|
Rex::Logger::debug($out); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
my $clone_cmd = sprintf( $CLONE_COMMAND, |
85
|
2
|
|
|
|
|
332
|
$clone_args, $repo_info->{"url"}, basename($checkout_to) ); |
86
|
2
|
|
|
|
|
98
|
Rex::Logger::debug( |
87
|
|
|
|
|
|
|
"clone_cmd: $clone_cmd (cwd: " . dirname($checkout_to) . ")" ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Rex::Logger::info( "Cloning " |
90
|
2
|
50
|
|
|
|
35
|
. $repo_info->{"url"} . " to " |
91
|
|
|
|
|
|
|
. ( $checkout_to ? $checkout_to : "." ) ); |
92
|
2
|
|
|
|
|
74
|
my $out = i_run "$clone_cmd", |
93
|
|
|
|
|
|
|
cwd => dirname($checkout_to), |
94
|
|
|
|
|
|
|
fail_ok => 1, |
95
|
|
|
|
|
|
|
%run_opt; |
96
|
2
|
50
|
|
|
|
80
|
unless ( $? == 0 ) { |
97
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Error cloning repository.", "warn" ); |
98
|
0
|
|
|
|
|
0
|
Rex::Logger::info($out); |
99
|
0
|
|
|
|
|
0
|
die("Error cloning repository."); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
54
|
Rex::Logger::debug($out); |
103
|
|
|
|
|
|
|
|
104
|
2
|
50
|
|
|
|
51
|
if ( exists $checkout_opt->{"branch"} ) { |
105
|
0
|
0
|
|
|
|
0
|
unless ($checkout_to) { |
106
|
0
|
|
|
|
|
0
|
$checkout_to = [ split( /\//, $repo_info->{"url"} ) ]->[-1]; |
107
|
0
|
|
|
|
|
0
|
$checkout_to =~ s/\.git$//; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $checkout_cmd = sprintf( |
111
|
|
|
|
|
|
|
$CHECKOUT_BRANCH_COMMAND, |
112
|
|
|
|
|
|
|
$checkout_opt->{"branch"}, |
113
|
0
|
|
|
|
|
0
|
$checkout_opt->{"branch"} |
114
|
|
|
|
|
|
|
); |
115
|
0
|
|
|
|
|
0
|
Rex::Logger::debug("checkout_cmd: $checkout_cmd"); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Switching to branch " . $checkout_opt->{"branch"} ); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
$out = i_run "$checkout_cmd", cwd => $checkout_to, fail_ok => 1, %run_opt; |
120
|
0
|
0
|
|
|
|
0
|
unless ( $? == 0 ) { |
121
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Error switching to branch.", "warn" ); |
122
|
0
|
|
|
|
|
0
|
Rex::Logger::info($out); |
123
|
0
|
|
|
|
|
0
|
die("Error switching to branch."); |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
0
|
Rex::Logger::debug($out); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
2
|
50
|
|
|
|
417
|
if ( exists $checkout_opt->{"tag"} ) { |
129
|
|
|
|
|
|
|
my $checkout_cmd = sprintf( |
130
|
|
|
|
|
|
|
$CHECKOUT_TAG_COMMAND, |
131
|
|
|
|
|
|
|
$checkout_opt->{"tag"}, |
132
|
0
|
|
|
|
|
|
$checkout_opt->{"tag"} |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
Rex::Logger::info( "Switching to tag " . $checkout_opt->{"tag"} ); |
136
|
0
|
|
|
|
|
|
$out = i_run "$checkout_cmd", cwd => $checkout_to, fail_ok => 1, %run_opt; |
137
|
0
|
0
|
|
|
|
|
unless ( $? == 0 ) { |
138
|
0
|
|
|
|
|
|
Rex::Logger::info( "Error switching to tag.", "warn" ); |
139
|
0
|
|
|
|
|
|
Rex::Logger::info($out); |
140
|
0
|
|
|
|
|
|
die("Error switching to tag."); |
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
|
Rex::Logger::debug($out); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |