... | ... |
@@ -1,182 +0,0 @@ |
1 |
-<% |
|
2 |
- |
|
3 |
- my $api = gitprep_api; |
|
4 |
- |
|
5 |
- my $user = param('user'); |
|
6 |
- my $project = param('project'); |
|
7 |
- my $remote_user = param('remote_user'); |
|
8 |
- my $remote_project = param('remote_project'); |
|
9 |
- my $remote_branch = param('remote-branch'); |
|
10 |
- |
|
11 |
- # Authentication |
|
12 |
- unless ($api->logined($user)) { |
|
13 |
- $self->redirect_to('/'); |
|
14 |
- return; |
|
15 |
- } |
|
16 |
- |
|
17 |
- # Branches |
|
18 |
- my $git = app->git; |
|
19 |
- my $remote_branches = $git->branches($self->app->rep_info($remote_user, $remote_project)); |
|
20 |
- my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
|
21 |
- |
|
22 |
- my $op = param('op') || ''; |
|
23 |
- my $errors; |
|
24 |
- if ($op eq 'import' && lc $self->req->method eq 'post') { |
|
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'); |
|
33 |
- |
|
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) { |
|
74 |
- |
|
75 |
- # Check branch name |
|
76 |
- my $branches = $git->branches($self->app->rep_info($user, $project)); |
|
77 |
- |
|
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."]; |
|
80 |
- } |
|
81 |
- else { |
|
82 |
- eval { |
|
83 |
- $git->import_branch( |
|
84 |
- app->rep_info($user, $project), |
|
85 |
- $branch, |
|
86 |
- app->rep_info($remote_user, $remote_project), |
|
87 |
- $remote_branch, |
|
88 |
- {force => $force} |
|
89 |
- ); |
|
90 |
- }; |
|
91 |
- |
|
92 |
- if (my $e = $@) { |
|
93 |
- $errors = ['Internal Error']; |
|
94 |
- app->log->error(url_for . ": $e"); |
|
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 |
- } |
|
101 |
- } |
|
102 |
- } |
|
103 |
- else { |
|
104 |
- $errors = $validation->messages; |
|
105 |
- } |
|
106 |
- } |
|
107 |
- |
|
108 |
- layout 'common', title => "Import branch"; |
|
109 |
-%> |
|
110 |
- |
|
111 |
- %= include 'include/header'; |
|
112 |
- |
|
113 |
- %= javascript begin |
|
114 |
- $('document').ready(function () { |
|
115 |
- |
|
116 |
- // Select remote branch |
|
117 |
- $('[name=copy-branch-name]').on('click', function () { |
|
118 |
- $('[name=branch]').val($('[name=remote-branch]').val()); |
|
119 |
- return false; |
|
120 |
- }); |
|
121 |
- }); |
|
122 |
- % end |
|
123 |
- |
|
124 |
- <div class="container"> |
|
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 |
- % } |
|
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 |
- % } |
|
139 |
- <h3 class="topic1">Import branch</h3> |
|
140 |
- <form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post"> |
|
141 |
- <div class="import-branch"> |
|
142 |
- <div class="left"> |
|
143 |
- <div class="import-branch-to"> |
|
144 |
- <div> |
|
145 |
- %= "$user / $project"; |
|
146 |
- </div> |
|
147 |
- <div> |
|
148 |
- %= text_field 'branch', placeholder => "Branch name", style => "width:250px"; |
|
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> |
|
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> |
|
162 |
- </div> |
|
163 |
- </div> |
|
164 |
- <div class="center"> |
|
165 |
- ⇐ |
|
166 |
- </div> |
|
167 |
- <div class="right"> |
|
168 |
- <div class="import-branch-from"> |
|
169 |
- <div> |
|
170 |
- %= "$remote_user / $remote_project"; |
|
171 |
- </div> |
|
172 |
- <div> |
|
173 |
- % param('remote-branch' => $remote_branch); |
|
174 |
- %= select_field 'remote-branch' => $remote_branch_names, style => "width:250px"; |
|
175 |
- </div> |
|
176 |
- </div> |
|
177 |
- </div> |
|
178 |
- </div> |
|
179 |
- </form> |
|
180 |
- </div> |
|
181 |
- |
|
182 |
- %= include '/include/footer'; |
... | ... |
@@ -70,18 +70,6 @@ |
70 | 70 |
location.href = '<%= url_for("/$user_id/$project_id/network/graph/") %>' + branch + '...' |
71 | 71 |
+ remote_member + '/' + remote_project + '/' + remote_branch; |
72 | 72 |
}); |
73 |
- |
|
74 |
- // Click import button |
|
75 |
- $('[name=import-btn]').on('click', function () { |
|
76 |
- var branch = $('[name=branch]').val(); |
|
77 |
- var remote = $(this).closest('[name=remote]'); |
|
78 |
- var remote_member = remote.find('[name=remote-member]').text(); |
|
79 |
- var remote_project = remote.find('[name=remote-project]').text(); |
|
80 |
- var remote_branch = remote.find('[name=remote-branch]').val(); |
|
81 |
- |
|
82 |
- location.href = '<%= url_for("/$user_id/$project_id/import-branch/") %>' |
|
83 |
- + remote_member + '/' + remote_project + '?remote-branch=' + remote_branch; |
|
84 |
- }); |
|
85 | 73 |
}); |
86 | 74 |
% end |
87 | 75 |
|
... | ... |
@@ -119,9 +107,6 @@ |
119 | 107 |
</div> |
120 | 108 |
<div class="last-child"> |
121 | 109 |
<button name="compare-btn" class="btn" style="margin-top:5px">Compare</button> |
122 |
- % if ($api->logined($user_id)) { |
|
123 |
- <button name="import-btn" class="btn" style="margin-top:5px">Import</button> |
|
124 |
- % } |
|
125 | 110 |
</div> |
126 | 111 |
</li> |
127 | 112 |
% } |
... | ... |
@@ -498,75 +498,6 @@ note 'Delete branch'; |
498 | 498 |
$t->content_unlike(qr/tmp_branch/); |
499 | 499 |
} |
500 | 500 |
|
501 |
-note 'import-branch'; |
|
502 |
-{ |
|
503 |
- system("$FindBin::Bin/../setup_database", $db_file) == 0 |
|
504 |
- or die "Can't setup $db_file"; |
|
505 |
- my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep"); |
|
506 |
- |
|
507 |
- my $t = Test::Mojo->new($app); |
|
508 |
- $t->ua->max_redirects(3); |
|
509 |
- |
|
510 |
- # Login as kimoto1 |
|
511 |
- $t->post_ok('/_login?op=login', form => {id => 'kimoto1', password => 'a'}); |
|
512 |
- $t->get_ok('/')->content_like(qr/Logined as kimoto1 /); |
|
513 |
- |
|
514 |
- # Create project |
|
515 |
- $t->post_ok('/_new?op=create', form => {project => 'import-branch1', description => '', readme => 1}); |
|
516 |
- $t->get_ok('/kimoto1')->content_like(qr/import-branch1/); |
|
517 |
- |
|
518 |
- # Login as kimoto2 |
|
519 |
- $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'}); |
|
520 |
- $t->get_ok('/')->content_like(qr/Logined as kimoto2 /); |
|
521 |
- |
|
522 |
- # Fork kimoto1/import-branch1 |
|
523 |
- $t->get_ok("/kimoto1/import-branch1/fork"); |
|
524 |
- $t->content_like(qr#Repository is forked from /kimoto1/import-branch1#); |
|
525 |
- |
|
526 |
- # Access not valid user |
|
527 |
- $t->get_ok('/kimoto1/import-branch1/network'); |
|
528 |
- $t->content_like(qr/Network/); |
|
529 |
- $t->content_unlike(qr/Import/); |
|
530 |
- $t->get_ok('/kimoto1/import-branch1/import-branch/kimoto2/import-branch1?remote-branch=master'); |
|
531 |
- $t->content_like(qr/ Index page /); |
|
532 |
- |
|
533 |
- # Show network page import button |
|
534 |
- $t->get_ok('/kimoto2/import-branch1/network'); |
|
535 |
- $t->content_like(qr/Network/); |
|
536 |
- $t->content_like(qr/Import/); |
|
537 |
- |
|
538 |
- # Import branch page access |
|
539 |
- $t->get_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?remote-branch=master'); |
|
540 |
- $t->content_like(qr/Import branch/); |
|
541 |
- |
|
542 |
- # Invalid parameters |
|
543 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?remote-branch=master&op=import'); |
|
544 |
- $t->content_like(qr/Branch name is empty/); |
|
545 |
- |
|
546 |
- # Import branch |
|
547 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
548 |
- branch => 'new1', |
|
549 |
- 'remote-branch' => 'master' |
|
550 |
- }); |
|
551 |
- $t->content_like(qr#Success: import#); |
|
552 |
- $t->get_ok('/kimoto2/import-branch1/branches')->content_like(qr/new1/); |
|
553 |
- |
|
554 |
- # Import same name branch fail |
|
555 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
556 |
- branch => 'new1', |
|
557 |
- 'remote-branch' => 'master' |
|
558 |
- }); |
|
559 |
- $t->content_like(qr#already exists#); |
|
560 |
- |
|
561 |
- # Import force |
|
562 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
563 |
- branch => 'new1', |
|
564 |
- 'remote-branch' => 'master', |
|
565 |
- force => 1 |
|
566 |
- }); |
|
567 |
- $t->content_like(qr#Success: force import#); |
|
568 |
-} |
|
569 |
- |
|
570 | 501 |
note 'Private repository and collaborator'; |
571 | 502 |
{ |
572 | 503 |
unlink $db_file; |