summaryrefslogtreecommitdiffstats
path: root/lib/Devscripts/Salsa/push_repo.pm
blob: 511316d5b8a4709a403fbd98bc778047c06190ca (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
# Creates GitLab project from local repository path
package Devscripts::Salsa::push_repo;

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

with "Devscripts::Salsa::create_repo";    # create_project

sub push_repo {
    my ($self, $reponame) = @_;
    unless ($reponame) {
        ds_warn "Repository path is missing";
        return 1;
    }
    unless (-d $reponame) {
        ds_warn "$reponame isn't a directory";
        return 1;
    }
    chdir $reponame;
    eval {
        spawn(
            exec       => ['dpkg-parsechangelog', '--show-field', 'Source'],
            to_string  => \$reponame,
            wait_child => 1,
        );
    };
    if ($@) {
        ds_warn $@;
        return 1;
    }
    chomp $reponame;
    my $out;
    spawn(
        exec       => ['git', 'remote', 'show'],
        to_string  => \$out,
        wait_child => 1,
    );
    if ($out =~ /^origin$/m) {
        ds_warn "git origin is already configured:\n$out";
        return 1;
    }
    my $path = $self->project2path('') or return 1;
    my $url  = $self->config->git_server_url . "$path$reponame";
    spawn(
        exec       => ['git', 'remote', 'add', 'origin', $url],
        wait_child => 1,
    );
    my $res = $self->create_repo($reponame);
    if ($res) {
        return 1
          unless (
            ds_prompt(
"Project already exists, do you want to try to push local repository? (y/N) "
            ) =~ accept
          );
    }
    spawn(
        exec =>
          ['git', 'push', '--all', '--verbose', '--set-upstream', 'origin'],
        wait_child => 1,
    );
    spawn(
        exec       => ['git', 'push', '--tags', '--verbose', 'origin'],
        wait_child => 1,
    );
    return 0;
}

1;