« blib/lib/Test/Smoke/Syncer/Snapshot.pm
↑ Summary
blib/lib/Test/Smoke/App/ConfigSmoke/SmokeEnv.pm »
| 1 | package Test::Smoke::Syncer::Git; | ||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 12 | our $VERSION = '0.029'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use base 'Test::Smoke::Syncer::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 Test::Smoke::Syncer::Git | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | This handles syncing with git repositories. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 12 | ▶ | use Test::Smoke::LogMixin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 12 | ▶ | use Test::Smoke::Util::Execute; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head2 Test::Smoke::Syncer::Git->new( %args ) | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Keys for C<%args>: | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | * gitorigin | ||||||||||||||||||||||||||||
| 26 | * gitdir | ||||||||||||||||||||||||||||
| 27 | * gitbin | ||||||||||||||||||||||||||||
| 28 | * gitbranchfile | ||||||||||||||||||||||||||||
| 29 | * gitdfbranch | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 $syncer->sync() | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Do the actual syncing. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | There are 2 repositories, they both need to be updated: | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | The first (mirror) repository has the github.com/Perl repository as its | ||||||||||||||||||||||||||||
| 40 | (origin) remote. The second repository is used to run the smoker from. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub sync { | ||||||||||||||||||||||||||
|
Subroutine
sync: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | ▶ | if ( $self->{gitbare} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $self->_sync_bare; | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 4 | $self->_sync_full_checkout; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | return $self->check_dot_patch; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head2 _sync_full_checkout() | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | For the proxy-repository we do: | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | git fetch --all | ||||||||||||||||||||||||||||
| 61 | git remote prune origin | ||||||||||||||||||||||||||||
| 62 | git reset --hard origin/$gitbranch | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | For the working-repository we do: | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | git clean -dfx | ||||||||||||||||||||||||||||
| 67 | git fetch --all | ||||||||||||||||||||||||||||
| 68 | git reset --hard origin/$gitbranch | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub _sync_full_checkout { | ||||||||||||||||||||||||||
|
Subroutine
_sync_full_checkout: called CC=12 SCAR=25.4
| |||||||||||||||||||||||||||||
| 73 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | my $gitbin = Test::Smoke::Util::Execute->new( | ||||||||||||||||||||||||||||
| 76 | command => $self->{gitbin}, | ||||||||||||||||||||||||||||
| 77 | 4 | verbose => $self->verbose, | |||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 4 | my $cwd = cwd(); | |||||||||||||||||||||||||||
| 81 | # Handle the proxy-clone | ||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if ( ! -d $self->{gitdir} || ! -d catdir($self->{gitdir}, '.git') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $self->{"gitdir"} and -d catdir($self->{"gitdir"}, ".git")
MC/DC50%1/2
-d $self->{"gitdir"} and -d catdir($self->{"gitdir"}, ".git")
-d $self->{"gitdir"}
-d catdir($self->{"gitdir"}, ".git")
Truth table66%2/3
A and B
A= -d $self->{"gitdir"}B= -d catdir($self->{"gitdir"}, ".git")
| |||||||||||||||||||||||||||||
| 83 | my $cloneout = $gitbin->run( | ||||||||||||||||||||||||||||
| 84 | clone => $self->{gitorigin}, | ||||||||||||||||||||||||||||
| 85 | $self->{gitdir}, | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | ($^O eq 'MSWin32' ? ('--config', 'core.autocrlf=input') : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | '2>&1' | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | 1 | ▶ | if ( my $gitexit = $gitbin->exitcode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | croak("Cannot make initial clone: $self->{gitbin} exit $gitexit"); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 1 | $self->log_debug("[git clone from $self->{gitorigin}]: $cloneout"); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 4 | my $gitbranch = $self->get_git_branch; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | chdir $self->{gitdir} or croak("Cannot chdir($self->{gitdir}): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 4 | $self->log_debug("chdir($self->{gitdir})"); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 4 | my $gitout = $gitbin->run(remote => 'update', '--prune', '2>&1'); | |||||||||||||||||||||||||||
| 100 | 4 | $self->log_debug("gitorigin(update --prune): $gitout"); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | $gitout = $gitbin->run(checkout => $gitbranch, '2>&1'); | |||||||||||||||||||||||||||
| 103 | 4 | $self->log_debug("gitorigin(checkout): $gitout"); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 4 | $gitout = $gitbin->run(reset => '--hard', "origin/$gitbranch", '2>&1'); | |||||||||||||||||||||||||||
| 106 | 4 | $self->log_debug("gitorigin(reset --hard): $gitout"); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Now handle the working-clone | ||||||||||||||||||||||||||||
| 109 | 4 | ▶ | chdir $cwd or croak("Cannot chdir($cwd): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 4 | $self->log_debug("chdir($cwd)"); | |||||||||||||||||||||||||||
| 111 | # make the working-clone if it doesn't exist yet | ||||||||||||||||||||||||||||
| 112 | 4 | ▶ | if ( ! -d $self->{ddir} || ! -d catdir($self->{ddir}, '.git') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $self->{"ddir"} and -d catdir($self->{"ddir"}, ".git")
MC/DC50%1/2
-d $self->{"ddir"} and -d catdir($self->{"ddir"}, ".git")
-d $self->{"ddir"}
-d catdir($self->{"ddir"}, ".git")
Truth table66%2/3
A and B
A= -d $self->{"ddir"}B= -d catdir($self->{"ddir"}, ".git")
| |||||||||||||||||||||||||||||
| 113 | # It needs to be empty ... | ||||||||||||||||||||||||||||
| 114 | my $cloneout = $gitbin->run( | ||||||||||||||||||||||||||||
| 115 | clone => $self->{gitdir}, | ||||||||||||||||||||||||||||
| 116 | $self->{ddir}, | ||||||||||||||||||||||||||||
| 117 | 1 | ▶ | ($^O eq 'MSWin32' ? ('--config', 'core.autocrlf=input') : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | '2>&1' | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | 1 | ▶ | if ( my $gitexit = $gitbin->exitcode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | croak("Cannot make smoke clone: $self->{gitbin} exit $gitexit"); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 1 | $self->log_debug("[git clone $self->{gitdir}]: $cloneout"); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 4 | ▶ | chdir $self->{ddir} or croak("Cannot chdir($self->{ddir}): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 4 | $self->log_debug("chdir($self->{ddir})"); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # reset the working-dir to HEAD of the last branch smoked | ||||||||||||||||||||||||||||
| 130 | 4 | $gitout = $gitbin->run(reset => '--hard', 'HEAD', '2>&1'); | |||||||||||||||||||||||||||
| 131 | 4 | $self->log_debug("working-dir(reset --hard): $gitout"); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # remove all untracked files and dirs | ||||||||||||||||||||||||||||
| 134 | 4 | $gitout = $gitbin->run(clean => '-dfx', '2>&1'); | |||||||||||||||||||||||||||
| 135 | 4 | $self->log_debug("working-dir(clean -dfx): $gitout"); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # update from origin | ||||||||||||||||||||||||||||
| 138 | 4 | $gitout = $gitbin->run(fetch => 'origin', '2>&1'); | |||||||||||||||||||||||||||
| 139 | 4 | $self->log_debug("working-dir(fetch origin): $gitout"); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # now checkout the branch we want smoked | ||||||||||||||||||||||||||||
| 142 | 4 | $gitout = $gitbin->run(checkout => $gitbranch, '2>&1'); | |||||||||||||||||||||||||||
| 143 | 4 | $self->log_debug("working-dir(checkout $gitbranch): $gitout"); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # Make sure HEAD is exactly what the branch is | ||||||||||||||||||||||||||||
| 146 | 4 | $gitout = $gitbin->run(reset => '--hard', "origin/$gitbranch", '2>&1'); | |||||||||||||||||||||||||||
| 147 | 4 | $self->log_debug("working-dir(reset --hard): $gitout"); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | $self->make_dot_patch(); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | chdir $cwd; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head2 _sync_bare() | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | For the mirror-repository we do: | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | git clone --mirror $gitorigin $gitdir # if not set up | ||||||||||||||||||||||||||||
| 160 | git remote update --prune | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | For the working-repository we do: | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | git clone --local $gitdir $ddir # if not set up | ||||||||||||||||||||||||||||
| 165 | git reset --hard HEAD | ||||||||||||||||||||||||||||
| 166 | git clean -dfx | ||||||||||||||||||||||||||||
| 167 | git fetch --all | ||||||||||||||||||||||||||||
| 168 | git reset --hard origin/$gitbranch | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub _sync_bare { | ||||||||||||||||||||||||||
|
Subroutine
_sync_bare: not called CC=13 SCAR=50.8
| |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | my $gitbin = Test::Smoke::Util::Execute->new( | ||||||||||||||||||||||||||||
| 176 | command => $self->{gitbin}, | ||||||||||||||||||||||||||||
| 177 | 0 | verbose => $self->verbose, | |||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||
| 179 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 180 | 0 | my $cwd = cwd(); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # Clean up if we weren't using a "bare" repo previously | ||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( -d catdir($self->{gitdir}, '.git') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | require File::Path; | |||||||||||||||||||||||||||
| 185 | File::Path::remove_tree( $self->{gitdir}, { | ||||||||||||||||||||||||||||
| 186 | 0 | verbose => $self->verbose, | |||||||||||||||||||||||||||
| 187 | } ); | ||||||||||||||||||||||||||||
| 188 | 0 | $self->log_debug("[Removed legacy gitdir]: $self->{gitdir}"); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # Handle the proxy-clone | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ( ! -d $self->{gitdir} || ! -d catdir($self->{gitdir}, 'objects') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $self->{"gitdir"} and -d catdir($self->{"gitdir"}, "objects")
MC/DC0%0/2
-d $self->{"gitdir"} and -d catdir($self->{"gitdir"}, "objects")
-d $self->{"gitdir"}
-d catdir($self->{"gitdir"}, "objects")
Truth table0%0/3
A and B
A= -d $self->{"gitdir"}B= -d catdir($self->{"gitdir"}, "objects")
| |||||||||||||||||||||||||||||
| 193 | my $cloneout = $gitbin->run( | ||||||||||||||||||||||||||||
| 194 | clone => '--mirror' => $self->{gitorigin}, | ||||||||||||||||||||||||||||
| 195 | $self->{gitdir}, | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | ($^O eq 'MSWin32' ? ('--config', 'core.autocrlf=input') : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | '2>&1' | ||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( my $gitexit = $gitbin->exitcode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | croak("Cannot make initial clone: $self->{gitbin} exit $gitexit"); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | $self->log_debug("[git clone from $self->{gitorigin}]: $cloneout"); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | chdir $self->{gitdir} or croak("Cannot chdir($self->{gitdir}): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | $self->log_debug("chdir($self->{gitdir})"); | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | my $gitout = $gitbin->run(remote => 'update', '--prune', '2>&1'); | |||||||||||||||||||||||||||
| 209 | 0 | $self->log_debug("gitorigin(update --prune): $gitout"); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $gitbranch = $self->get_git_branch; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # Now handle the working-clone | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | chdir $cwd or croak("Cannot chdir($cwd): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | $self->log_debug("chdir($cwd)"); | |||||||||||||||||||||||||||
| 216 | # make the working-clone if it doesn't exist yet | ||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ( ! -d $self->{ddir} || ! -d catdir($self->{ddir}, '.git') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $self->{"ddir"} and -d catdir($self->{"ddir"}, ".git")
MC/DC0%0/2
-d $self->{"ddir"} and -d catdir($self->{"ddir"}, ".git")
-d $self->{"ddir"}
-d catdir($self->{"ddir"}, ".git")
Truth table0%0/3
A and B
A= -d $self->{"ddir"}B= -d catdir($self->{"ddir"}, ".git")
| |||||||||||||||||||||||||||||
| 218 | # It needs to be empty ... | ||||||||||||||||||||||||||||
| 219 | my $cloneout = $gitbin->run( | ||||||||||||||||||||||||||||
| 220 | clone => '--local' => $self->{gitdir}, | ||||||||||||||||||||||||||||
| 221 | $self->{ddir}, | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | ($^O eq 'MSWin32' ? ('--config', 'core.autocrlf=input') : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | '2>&1' | ||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ( my $gitexit = $gitbin->exitcode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | croak("Cannot make smoke clone: $self->{gitbin} exit $gitexit"); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 0 | $self->log_debug("[git clone $self->{gitdir}]: $cloneout"); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | chdir $self->{ddir} or croak("Cannot chdir($self->{ddir}): $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | $self->log_debug("chdir($self->{ddir})"); | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # reset the working-dir to HEAD of the last branch smoked | ||||||||||||||||||||||||||||
| 235 | 0 | $gitout = $gitbin->run(reset => '--hard', 'HEAD', '2>&1'); | |||||||||||||||||||||||||||
| 236 | 0 | $self->log_debug("working-dir(reset --hard): $gitout"); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # remove all untracked files and dirs | ||||||||||||||||||||||||||||
| 239 | 0 | $gitout = $gitbin->run(clean => '-dfx', '2>&1'); | |||||||||||||||||||||||||||
| 240 | 0 | $self->log_debug("working-dir(clean -dfx): $gitout"); | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | # update from origin | ||||||||||||||||||||||||||||
| 243 | 0 | $gitout = $gitbin->run(fetch => '--all', '2>&1'); | |||||||||||||||||||||||||||
| 244 | 0 | $self->log_debug("working-dir(fetch --all): $gitout"); | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # now checkout the branch we want smoked | ||||||||||||||||||||||||||||
| 247 | 0 | $gitout = $gitbin->run(checkout => $gitbranch, '2>&1'); | |||||||||||||||||||||||||||
| 248 | 0 | $self->log_debug("working-dir(checkout $gitbranch): $gitout"); | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # Make sure HEAD is exactly what the branch is | ||||||||||||||||||||||||||||
| 251 | 0 | $gitout = $gitbin->run(reset => '--hard', "origin/$gitbranch", '2>&1'); | |||||||||||||||||||||||||||
| 252 | 0 | $self->log_debug("working-dir(reset --hard): $gitout"); | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | $self->make_dot_patch(); | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | chdir $cwd; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head2 $git->get_git_branch() | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | Reads the first line of the file set in B<gitbranchfile> and returns its | ||||||||||||||||||||||||||||
| 263 | value. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 5 | ▶ | sub get_git_branch { | ||||||||||||||||||||||||||
|
Subroutine
get_git_branch: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 268 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 5 | ▶ | return $self->{gitdfbranch} if !$self->{gitbranchfile}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 5 | ▶ | return $self->{gitdfbranch} if ! -f $self->{gitbranchfile}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 5 | ▶ | if (open my $fh, '<', $self->{gitbranchfile}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 5 | $self->log_debug("Reading branch to smoke from: '$self->{gitbranchfile}'"); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 5 | chomp( my $branch = <$fh> ); | |||||||||||||||||||||||||||
| 277 | 5 | close $fh; | |||||||||||||||||||||||||||
| 278 | 5 | return $branch; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | 0 | $self->log_warn("Error opening '$self->{gitbranchfile}': $!"); | |||||||||||||||||||||||||||
| 281 | 0 | return $self->{gitdfbranch}; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 12 | 1; | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | (c) 2002-2013, All rights reserved. | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 293 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | See: | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | * <http://www.perl.com/perl/misc/Artistic.html>, | ||||||||||||||||||||||||||||
| 298 | * <http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 301 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 302 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||||||||