<% my $api = gitprep_api; my $user = param('user'); my $project = param('project'); my $remote_user = param('remote_user'); my $remote_project = param('remote_project'); my $remote_branch = param('remote-branch'); # Authentication unless ($api->logined($user)) { $self->redirect_to('/'); return; } # Branches my $git = app->git; my $remote_branches = $git->branches($self->app->rep_info($remote_user, $remote_project)); my $remote_branch_names = [map { $_->{name} } @$remote_branches]; my $op = param('op') || ''; my $errors; if ($op eq 'import' && lc $self->req->method eq 'post') { # Parameters my $user = param('user'); my $project = param('project'); my $branch = param('branch'); my $remote_user = param('remote_user'); my $remote_project = param('remote_project'); my $remote_branch = param('remote-branch'); my $force = param('force'); # Validator my $vc = app->vc; # Validation result my $validation = $vc->validation; # "user" if (!$vc->check($user, 'user_name')) { $validation->add_failed('User name is invalid.'); } # "project" if (!$vc->check($project, 'project_name')) { $validation->add_failed('Repository name is invalid.'); } # "branch" if (!(defined $branch && length $branch)) { $validation->add_failed('Branch name is empty.'); } # "remote_user" if (!$vc->check($remote_user, 'user_name')) { $validation->add_failed('Remote User name is invalid.'); } # "remote_project" if (!$vc->check($remote_project, 'project_name')) { $validation->add_failed('Remote repository is invalid.'); } # "remote-branch" if (!(defined $remote_branch && length $remote_branch)) { $validation->add_failed('Remote branch name is empty.'); } # "force" $force = $force ? 1 : 0; if ($validation->is_valid) { # Check branch name my $branches = $git->branches($self->app->rep_info($user, $project)); if (!$force && grep { $branch eq $_->{name} } @$branches) { $errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; } else { eval { $git->import_branch( app->rep_info($user, $project), $branch, app->rep_info($remote_user, $remote_project), $remote_branch, {force => $force} ); }; if (my $e = $@) { $errors = ['Internal Error']; app->log->error(url_for . ": $e"); } else { flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); $self->redirect_to('current'); return; } } } else { $errors = $validation->messages; } } layout 'common', title => "Import branch"; %> %= include 'include/header'; %= javascript begin $('document').ready(function () { // Select remote branch $('[name=copy-branch-name]').on('click', function () { $('[name=branch]').val($('[name=remote-branch]').val()); return false; }); }); % end
% if (my $message = flash('message')) {
<%= $message %>
% } % if ($errors) {
% for my $error (@$errors) {

<%= $error %>

% }
% }

Import branch

query(op => 'import') %>" method="post">
%= "$user / $project";
%= text_field 'branch', placeholder => "Branch name", style => "width:250px";
%= submit_button 'Import', class => "btn btn-info";
<%= check_box force => 1 %>
Force
%= "$remote_user / $remote_project";
% param('remote-branch' => $remote_branch); %= select_field 'remote-branch' => $remote_branch_names, style => "width:250px";
%= include '/include/footer';