| 1 | # | ||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Rex::Commands::SCM - Sourcecontrol for Subversion and Git. | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | With this module you can checkout subversion and git repositories. | ||||||||||
| 12 | |||||||||||
| 13 | Version <= 1.0: All these functions will not be reported. | ||||||||||
| 14 | |||||||||||
| 15 | All these functions are not idempotent. | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | use Rex::Commands::SCM; | ||||||||||
| 20 | |||||||||||
| 21 | set repository => "myrepo", | ||||||||||
| 22 | url => 'git@foo.bar:myrepo.git'; | ||||||||||
| 23 | |||||||||||
| 24 | set repository => "myrepo2", | ||||||||||
| 25 | url => "https://foo.bar/myrepo", | ||||||||||
| 26 | type => "subversion", | ||||||||||
| 27 | username => "myuser", | ||||||||||
| 28 | password => "mypass"; | ||||||||||
| 29 | |||||||||||
| 30 | task "checkout", sub { | ||||||||||
| 31 | checkout "myrepo"; | ||||||||||
| 32 | |||||||||||
| 33 | checkout "myrepo", | ||||||||||
| 34 | path => "webapp"; | ||||||||||
| 35 | |||||||||||
| 36 | checkout "myrepo", | ||||||||||
| 37 | path => "webapp", | ||||||||||
| 38 | branch => 1.6; # branch only for git | ||||||||||
| 39 | |||||||||||
| 40 | # For Git only, will replay any local commits on top of pulled commits | ||||||||||
| 41 | checkout "myrepo", | ||||||||||
| 42 | path => "script_dir", | ||||||||||
| 43 | rebase => TRUE; | ||||||||||
| 44 | |||||||||||
| 45 | checkout "myrepo2"; | ||||||||||
| 46 | }; | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | =head1 EXPORTED FUNCTIONS | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | package Rex::Commands::SCM; | ||||||||||
| 54 | |||||||||||
| 55 | 2 | ▶ | use v5.14.4; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 57 | |||||||||||
| 58 | 2 | our $VERSION = '1.16.1'; # VERSION | |||||||||
| 59 | |||||||||||
| 60 | 2 | ▶ | use Rex::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 2 | ▶ | use Rex::Config; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | 2 | require Rex::Exporter; | |||||||||
| 64 | 2 | ▶ | use base qw(Rex::Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | 2 | ▶ | use vars qw(@EXPORT %REPOS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 2 | @EXPORT = qw(checkout); | |||||||||
| 67 | |||||||||||
| 68 | Rex::Config->register_set_handler( | ||||||||||
| 69 | 1 | ▶ | "repository" => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | my ( $name, %option ) = @_; | |||||||||
| 71 | 1 | $REPOS{$name} = \%option; | |||||||||
| 72 | } | ||||||||||
| 73 | 2 | ); | |||||||||
| 74 | |||||||||||
| 75 | =head2 checkout($name, %data); | ||||||||||
| 76 | |||||||||||
| 77 | With this function you can checkout a repository defined with I<set repository>. See Synopsis. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 13 | ▶ | sub checkout { | ||||||||
|
Subroutine
checkout: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 82 | 13 | my ( $name, %data ) = @_; | |||||||||
| 83 | |||||||||||
| 84 | 13 | ▶ | my $type = $REPOS{"$name"}->{"type"} ? $REPOS{$name}->{"type"} : "git"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 13 | my $class = "Rex::SCM::\u$type"; | |||||||||
| 86 | |||||||||||
| 87 | 13 | ▶ | my $co_to = exists $data{"path"} ? $data{"path"} : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | |||||||||||
| 89 | 13 | ▶ | if ( $data{"path"} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 13 | $data{"path"} = undef; | |||||||||
| 91 | 13 | delete $data{"path"}; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 13 | ▶ | eval "use $class;"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 95 | 13 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | Rex::Logger::info( "Error loading SCM: $@\n", "warn" ); | |||||||||
| 97 | 0 | die("Error loading SCM: $@"); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 13 | my $scm = $class->new; | |||||||||
| 101 | |||||||||||
| 102 | 13 | my $repo = Rex::Config->get("repository"); | |||||||||
| 103 | 13 | Rex::Logger::debug("Checking out $repo -> $co_to"); | |||||||||
| 104 | 13 | $scm->checkout( $REPOS{$name}, $co_to, \%data ); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 2 | 1; | |||||||||