change pull feature to impor...
|
1 |
<% |
add import-branch authentica...
|
2 |
|
3 |
my $api = gitprep_api; |
|
4 |
|
|
change pull feature to impor...
|
5 |
my $user = param('user'); |
6 |
my $project = param('project'); |
|
add import branch tests
|
7 |
my $remote_user = param('remote_user'); |
8 |
my $remote_project = param('remote_project'); |
|
9 |
my $remote_branch = param('remote-branch'); |
|
add import-branch authentica...
|
10 |
|
11 |
# Authentication |
|
12 |
unless ($api->logined($user)) { |
|
13 |
$self->redirect_to('/'); |
|
14 |
return; |
|
15 |
} |
|
change pull feature to impor...
|
16 |
|
17 |
# Branches |
|
revert encoding support
|
18 |
my $git = app->git; |
cleanup rep_info
|
19 |
my $remote_branches = $git->branches($self->app->rep_info($remote_user, $remote_project)); |
change pull feature to impor...
|
20 |
my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
21 |
|
|
22 |
my $op = param('op') || ''; |
|
23 |
my $errors; |
|
improve import-branch page d...
|
24 |
if ($op eq 'import' && lc $self->req->method eq 'post') { |
cleanup import-branch valida...
|
25 |
# Parameters |
26 |
my $user = param('user'); |
|
27 |
my $project = param('project'); |
|
28 |
my $branch = param('branch'); |
|
29 |
my $remote_user = param('remote_user'); |
|
30 |
my $remote_project = param('remote_project'); |
|
31 |
my $remote_branch = param('remote-branch'); |
|
32 |
my $force = param('force'); |
|
change pull feature to impor...
|
33 |
|
cleanup import-branch valida...
|
34 |
# Validator |
35 |
my $vc = app->vc; |
|
36 |
|
|
37 |
# Validation result |
|
38 |
my $validation = $vc->validation; |
|
39 |
|
|
40 |
# "user" |
|
41 |
if (!$vc->check($user, 'user_name')) { |
|
42 |
$validation->add_failed('User name is invalid.'); |
|
43 |
} |
|
44 |
|
|
45 |
# "project" |
|
46 |
if (!$vc->check($project, 'project_name')) { |
|
47 |
$validation->add_failed('Repository name is invalid.'); |
|
48 |
} |
|
49 |
|
|
50 |
# "branch" |
|
51 |
if (!(defined $branch && length $branch)) { |
|
52 |
$validation->add_failed('Branch name is empty.'); |
|
53 |
} |
|
54 |
|
|
55 |
# "remote_user" |
|
56 |
if (!$vc->check($remote_user, 'user_name')) { |
|
57 |
$validation->add_failed('Remote User name is invalid.'); |
|
58 |
} |
|
59 |
|
|
60 |
# "remote_project" |
|
61 |
if (!$vc->check($remote_project, 'project_name')) { |
|
62 |
$validation->add_failed('Remote repository is invalid.'); |
|
63 |
} |
|
64 |
|
|
65 |
# "remote-branch" |
|
66 |
if (!(defined $remote_branch && length $remote_branch)) { |
|
67 |
$validation->add_failed('Remote branch name is empty.'); |
|
68 |
} |
|
69 |
|
|
70 |
# "force" |
|
71 |
$force = $force ? 1 : 0; |
|
72 |
|
|
73 |
if ($validation->is_valid) { |
|
change pull feature to impor...
|
74 |
|
complete branch import featu...
|
75 |
# Check branch name |
cleanup rep_info
|
76 |
my $branches = $git->branches($self->app->rep_info($user, $project)); |
improve import-branch page d...
|
77 |
|
complete branch import featu...
|
78 |
if (!$force && grep { $branch eq $_->{name} } @$branches) { |
79 |
$errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; |
|
improve import-branch page d...
|
80 |
} |
81 |
else { |
|
complete branch import featu...
|
82 |
eval { |
83 |
$git->import_branch( |
|
cleanup import_branch
|
84 |
app->rep_info($user, $project), |
complete branch import featu...
|
85 |
$branch, |
cleanup import_branch
|
86 |
app->rep_info($remote_user, $remote_project), |
complete branch import featu...
|
87 |
$remote_branch, |
88 |
{force => $force} |
|
89 |
); |
|
90 |
}; |
|
91 |
|
|
cleanup import-branch valida...
|
92 |
if (my $e = $@) { |
complete branch import featu...
|
93 |
$errors = ['Internal Error']; |
cleanup import-branch valida...
|
94 |
app->log->error(url_for . ": $e"); |
complete branch import featu...
|
95 |
} |
96 |
else { |
|
97 |
flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
98 |
$self->redirect_to('current'); |
|
99 |
return; |
|
100 |
} |
|
improve import-branch page d...
|
101 |
} |
change pull feature to impor...
|
102 |
} |
103 |
else { |
|
cleanup import-branch valida...
|
104 |
$errors = $validation->messages; |
change pull feature to impor...
|
105 |
} |
106 |
} |
|
improve import-branch page d...
|
107 | |
108 |
layout 'common', title => "Import branch"; |
|
change pull feature to impor...
|
109 |
%> |
110 | ||
111 |
%= include 'include/header'; |
|
improve import-branch page d...
|
112 | |
change pull feature to impor...
|
113 |
%= javascript begin |
114 |
$('document').ready(function () { |
|
115 |
|
|
116 |
// Select remote branch |
|
117 |
$('[name=copy-branch-name]').on('click', function () { |
|
improve import-branch page d...
|
118 |
$('[name=branch]').val($('[name=remote-branch]').val()); |
change pull feature to impor...
|
119 |
return false; |
120 |
}); |
|
121 |
}); |
|
122 |
% end |
|
123 |
|
|
124 |
<div class="container"> |
|
improve import-branch page d...
|
125 |
% if (my $message = flash('message')) { |
126 |
<div class="alert alert-success"> |
|
127 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
128 |
<%= $message %> |
|
129 |
</div> |
|
130 |
% } |
|
change pull feature to impor...
|
131 |
% if ($errors) { |
132 |
<div class="alert alert-error"> |
|
133 |
<button type="button" class="close" data-dismiss="alert">×</button> |
|
134 |
% for my $error (@$errors) { |
|
135 |
<p><%= $error %></p> |
|
136 |
% } |
|
137 |
</div> |
|
138 |
% } |
|
improve import-branch page d...
|
139 |
<h3 class="topic1">Import branch</h3> |
add import branch tests
|
140 |
<form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post"> |
improve import-branch page d...
|
141 |
<div class="import-branch"> |
142 |
<div class="left"> |
|
143 |
<div class="import-branch-to"> |
|
144 |
<div> |
|
change pull feature to impor...
|
145 |
%= "$user / $project"; |
146 |
</div> |
|
147 |
<div> |
|
improve import-branch page d...
|
148 |
%= text_field 'branch', placeholder => "Branch name", style => "width:250px"; |
improve import-branch page d...
|
149 |
<button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button> |
150 |
</div> |
|
improve import-branch page d...
|
151 |
<div class="import-branch-button-panel"> |
152 |
<div> |
|
153 |
%= submit_button 'Import', class => "btn btn-info"; |
|
154 |
</div> |
|
155 |
<div> |
|
156 |
<%= check_box force => 1 %> |
|
157 |
</div> |
|
158 |
<div> |
|
159 |
Force |
|
160 |
</div> |
|
161 |
</div> |
|
change pull feature to impor...
|
162 |
</div> |
163 |
</div> |
|
improve import-branch page d...
|
164 |
<div class="center"> |
165 |
⇐ |
|
change pull feature to impor...
|
166 |
</div> |
improve import-branch page d...
|
167 |
<div class="right"> |
168 |
<div class="import-branch-from"> |
|
169 |
<div> |
|
change pull feature to impor...
|
170 |
%= "$remote_user / $remote_project"; |
171 |
</div> |
|
improve import-branch page d...
|
172 |
<div> |
173 |
% param('remote-branch' => $remote_branch); |
|
174 |
%= select_field 'remote-branch' => $remote_branch_names, style => "width:250px"; |
|
175 |
</div> |
|
change pull feature to impor...
|
176 |
</div> |
177 |
</div> |
|
178 |
</div> |
|
179 |
</form> |
|
180 |
</div> |
|
181 |
|
|
182 |
%= include '/include/footer'; |