summaryrefslogtreecommitdiffstats
path: root/lib/Devscripts/Salsa/checkout.pm
blob: c3b5fe56564306f74c192e6a416ddf92007874eb (plain)
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
# Clones or updates a repository using gbp
# TODO: git-dpm ?
package Devscripts::Salsa::checkout;

use strict;
use Devscripts::Output;
use Devscripts::Utils;
use Dpkg::IPC;
use Moo::Role;

with "Devscripts::Salsa::Repo";

sub checkout {
    my ($self, @repos) = @_;
    unless (@repos or $self->config->all or $self->config->all_archived) {
        ds_warn "Usage $0 checkout <--all|--all-archived|names>";
        return 1;
    }
    if (@repos and $self->config->all) {
        ds_warn "--all with a reponame makes no sense";
        return 1;
    }
    if (@repos and $self->config->all_archived) {
        ds_warn "--all-archived with a reponame makes no sense";
        return 1;
    }
    # If --all is asked, launch all projects
    @repos = map { $_->[1] } $self->get_repo(0, @repos) unless (@repos);
    my $cdir = `pwd`;
    chomp $cdir;
    my $res = 0;
    foreach (@repos) {
        my $path = $self->project2path($_);
        s#.*/##;
        if (-d $_) {
            chdir $_;
            ds_verbose "Updating existing checkout in $_";
            spawn(
                exec       => ['gbp', 'pull', '--pristine-tar'],
                wait_child => 1,
                nocheck    => 1,
            );
            if ($?) {
                if ($self->config->no_fail) {
                    print STDERR "gbp pull fails in $_, "
                      . "continuing since --no-fail is set\n";
                    $res++;
                } else {
                    ds_warn "gbp pull failed in $_\n";
                    return 1;
                }
            }
            chdir $cdir;
        } else {
            spawn(
                exec => [
                    'gbp',   'clone',
                    '--all', $self->config->git_server_url . $path . ".git"
                ],
                wait_child => 1,
                nocheck    => 1,
            );
            if ($?) {
                if ($self->config->no_fail) {
                    print STDERR "gbp clone fails in $_, "
                      . "continuing since --no-fail is set\n";
                    $res++;
                } else {
                    ds_warn "gbp clone failed for $_\n";
                    return 1;
                }
            }
            ds_warn "$_ ready in $_/";
        }
    }
    return $res;
}

1;