<% # API my $api = gitprep_api; # Parameters my $user = param('user'); my $project = param('project'); my $op = param('op') || ''; # Git my $git = $self->app->git; # Delete my $errors; if ($op eq 'delete' && lc $self->req->method eq 'post') { # Forbbiden unless ($api->logined($user)) { $self->redirect_to('/'); return; } # Validation my $params = $api->params; my $vc = $self->app->vc; my $rule = [ branch => [ [not_blank => 'Branch name is empty'] ] ]; my $vresult = $vc->validate($params, $rule); if ($vresult->is_ok) { # Valid parameters my $params = $vresult->data; my $branch = $params->{branch}; # Delete branch eval { $git->delete_branch($user, $project, $branch) }; if ($@) { app->log->error(url_with . ":$@"); $errors = ['Internal Error']; } else { $self->flash(message => "Branch $branch is deleted."); $self->redirect_to; return; } } else { $errors = $vresult->messages } } # Default branch my $base_branch_name = param('base_branch') || app->manager->default_branch($user, $project); my $base_branch = $git->branch($user, $project, $base_branch_name); # No merged branches my $branches = $git->branches($user, $project); my $max = 0; for my $branch (@$branches) { $branch->{status} = $git->branch_status($user, $project, $base_branch->{name}, $branch->{name}); $max = $branch->{status}{ahead} if $max < $branch->{status}{ahead}; $max = $branch->{status}{behind} if $max < $branch->{status}{behind}; } my $branches_count = $git->branches_count($user, $project); my $no_merged_branches_count = $git->no_merged_branches_count($user, $project); my $merged_branches_count = $branches_count - $no_merged_branches_count - 1; # Global variable stash(rev => $base_branch_name); %> % layout 'common', title => "branches \x{30fb} $user/$project"; %= javascript begin $('document').ready(function () { // Swich merged branch or not merged branch var display_no_merged = true; $('#toggle-branch').on('click', function () { if (display_no_merged) { $(this).text('View unmerged branches'); $('#no-merged-branch-message').hide(); $('#merged-branch-message').show(); $('.no-merged-branch').css('display', 'none'); $('.merged-branch').css('display', 'block'); } else { $(this).text('View merged branches'); $('#no-merged-branch-message').show(); $('#merged-branch-message').hide(); $('.no-merged-branch').css('display', 'block'); $('.merged-branch').css('display', 'none'); } display_no_merged = !display_no_merged; }); // Click delete button $('.delete-branch').on('click', function () { if (window.confirm('Are you sure you want to remove this branch?')) { return true; } else { return false; } }); }); % end %= include '/include/header';
%= include '/include/errors', errors => $errors; %= include '/include/message', message => flash('message'); %= include '/include/project_header'; %= include '/include/code_menu', display => 'branches', branches => $branches;

Branches

Showing <%= $no_merged_branches_count %> branches not merged into <%= $base_branch->{name} %>. View merged branches
<%= $base_branch->{name} %>
Last updated <%= $base_branch->{commit}{age_string} %> by <%= $base_branch->{commit}{author_name} %>
Base branch
% for (my $i = 0; $i < @$branches; $i++) { % my $branch = $branches->[$i]; % my $bname = $branch->{name}; % next if $bname eq $base_branch->{name};
"> <%= $bname %>
Last updated <%= $branch->{commit}{age_string} %> by <%= $branch->{commit}{author_name} %>
<%= $branch->{status}{ahead} %> ahead
<%= $branch->{status}{behind} %> behind
% if ($api->logined($user)) {
%= hidden_field branch => $bname;
% } {name}...$bname") %>"> Compare
% }
%= include '/include/footer';