File: Subversion.pm

package info (click to toggle)
rex 1.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,012 kB
  • sloc: perl: 35,587; xml: 264; sh: 51; makefile: 13
file content (79 lines) | stat: -rw-r--r-- 1,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package Rex::SCM::Subversion;

use v5.12.5;
use warnings;

our $VERSION = '1.14.1'; # VERSION

use Cwd qw(getcwd);
use Rex::Commands::Fs;
use Rex::Helper::Run;

use vars qw($CHECKOUT_COMMAND);

BEGIN {
  my $version = qx{svn --version --quiet 2>/dev/null};
  if ($version) {
    my @parts = split( /\./, $version );

    if ( $parts[1] <= 5 ) {
      $CHECKOUT_COMMAND = "svn --non-interactive %s checkout %s %s";
    }
    else {
      $CHECKOUT_COMMAND =
        "svn --non-interactive --trust-server-cert %s checkout %s %s";
    }
  }
}

sub new {
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = {@_};

  bless( $self, $proto );

  return $self;
}

sub checkout {
  my ( $self, $repo_info, $checkout_to, $checkout_opt ) = @_;

  my $special_opts = "";

  if ( exists $repo_info->{"username"} ) {
    $special_opts = " --username  '" . $repo_info->{"username"} . "'";
  }

  if ( exists $repo_info->{"password"} ) {
    $special_opts .= " --password  '" . $repo_info->{"password"} . "'";
  }

  my $checkout_cmd;

  if ( !is_dir($checkout_to) ) {
    $checkout_cmd = sprintf( $CHECKOUT_COMMAND,
      $special_opts, $repo_info->{"url"}, $checkout_to );
  }
  elsif ( is_dir("$checkout_to/.svn") ) {
    $checkout_cmd = "svn up $checkout_to";
  }
  else {
    Rex::Logger::info( "Error checking out repository.", "warn" );
    die("Error checking out repository.");
  }
  Rex::Logger::debug("checkout_cmd: $checkout_cmd");

  Rex::Logger::info( "Cloning "
      . $repo_info->{"url"} . " to "
      . ( $checkout_to ? $checkout_to : "." ) );
  my $out = i_run "$checkout_cmd", fail_ok => 1;
  unless ( $? == 0 ) {
    Rex::Logger::info( "Error checking out repository.", "warn" );
    Rex::Logger::info($out);
    die("Error checking out repository.");
  }

}

1;