fixed tags page paging bug a...
|
1 |
package Gitprep::Manager; |
2 |
use Mojo::Base -base; |
|
3 | ||
4 |
use Carp 'croak'; |
|
fixed bug that setting page ...
|
5 |
use Encode 'encode'; |
fix description file not cop...
|
6 |
use File::Copy qw/move copy/; |
fixed tags page paging bug a...
|
7 |
use File::Path qw/mkpath rmtree/; |
8 |
use File::Temp (); |
|
add key delete feature and u...
|
9 |
use Fcntl ':flock'; |
10 |
use Carp 'croak'; |
|
11 |
use File::Copy qw/copy move/; |
|
fix bug that in CGI reposito...
|
12 |
use File::Spec; |
13 |
use Gitprep::Util; |
|
fixed tags page paging bug a...
|
14 | |
15 |
has 'app'; |
|
add key delete feature and u...
|
16 |
has 'authorized_keys_file'; |
fixed tags page paging bug a...
|
17 | |
add lock system
|
18 |
sub lock_rep { |
19 |
my ($self, $rep_info) = @_; |
|
20 |
|
|
21 |
my $git_dir = $rep_info->{git_dir}; |
|
22 |
my $lock_file = "$git_dir/config"; |
|
23 |
|
|
24 |
open my $lock_fh, '<', $lock_file |
|
25 |
or croak "Can't open lock file $lock_file: $!"; |
|
26 |
|
|
27 |
flock $lock_fh, LOCK_EX |
|
28 |
or croak "Can't lock $lock_file"; |
|
29 |
|
|
30 |
return $lock_fh; |
|
31 |
} |
|
32 | ||
add automatical merge checki...
|
33 |
sub check_merge_automatical { |
34 |
my ($self, $rep_info, $branch1, $branch2) = @_; |
|
35 |
|
|
36 |
# Create patch |
|
37 |
my @git_format_patch_cmd = $self->app->git->cmd( |
|
38 |
$rep_info, |
|
39 |
'format-patch', |
|
40 |
"$branch1..$branch2", |
|
41 |
"--stdout" |
|
42 |
); |
|
43 |
open my $git_format_patch_fh, '-|', @git_format_patch_cmd |
|
44 |
or Carp::croak "Can't execute git format-patch: @git_format_patch_cmd"; |
|
45 |
my $patch_str = do { local $/; <$git_format_patch_fh> }; |
|
46 |
|
|
47 |
# Write patch to file |
|
48 |
my $tmp_dir = File::Temp->newdir(DIR => $self->app->home->rel_file('/tmp')); |
|
49 |
my $patch_file = "$tmp_dir/test.patch"; |
|
50 |
open my $patch_fh, '>', $patch_file |
|
51 |
or Carp::croak "Can't open patch file $patch_file: $!"; |
|
52 |
print $patch_fh $patch_str; |
|
53 |
close $patch_fh; |
|
54 |
|
|
55 |
# Check if this patch can be applied |
|
56 |
my @git_apply_cmd = $self->app->git->cmd( |
|
57 |
$rep_info, |
|
58 |
'apply', |
|
59 |
$patch_file, |
|
60 |
'--check' |
|
61 |
); |
|
62 |
my $automatical = Gitprep::Util::run_command(@git_apply_cmd); |
|
63 |
|
|
64 |
return $automatical; |
|
65 |
} |
|
66 | ||
cleanup
|
67 |
sub create_work_rep { |
improve create working repos...
|
68 |
my ($self, $user, $project) = @_; |
69 |
|
|
cleanup create working direc...
|
70 |
# Remote repository |
71 |
my $rep_info = $self->app->rep_info($user, $project); |
|
72 |
my $rep_git_dir = $rep_info->{git_dir}; |
|
73 |
|
|
74 |
# Working repository |
|
75 |
my $work_rep_info = $self->app->work_rep_info($user, $project); |
|
76 |
my $work_tree = $work_rep_info->{work_tree}; |
|
77 |
|
|
improve create working repos...
|
78 |
# Create working repository if it don't exist |
cleanup create working direc...
|
79 |
unless (-e $work_tree) { |
80 | ||
improve create working repos...
|
81 |
# git clone |
cleanup create working direc...
|
82 |
my @git_clone_cmd = ($self->app->git->bin, 'clone', $rep_git_dir, $work_tree); |
improve create working repos...
|
83 |
Gitprep::Util::run_command(@git_clone_cmd) |
84 |
or croak "Can't git clone: @git_clone_cmd"; |
|
cleanup compare logic
|
85 |
|
86 |
# Create temparary branch |
|
87 |
my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__'; |
|
88 |
my @git_branch_cmd = $self->app->git->cmd( |
|
89 |
$work_rep_info, |
|
90 |
'branch', |
|
91 |
$gitprep_tmp_branch_name, |
|
92 |
); |
|
93 |
Gitprep::Util::run_command(@git_branch_cmd) |
|
94 |
or Carp::croak "Can't execute git branch: @git_branch_cmd"; |
|
improve create working repos...
|
95 | |
96 |
# Set user name |
|
cleanup create working direc...
|
97 |
my @git_config_user_name = $self->app->git->cmd( |
98 |
$work_rep_info, |
|
improve create working repos...
|
99 |
'config', |
100 |
'user.name', |
|
101 |
$user |
|
102 |
); |
|
103 |
Gitprep::Util::run_command(@git_config_user_name) |
|
104 |
or croak "Can't execute git config: @git_config_user_name"; |
|
105 |
|
|
fix mail bug
|
106 |
# Set user email |
107 |
my $user_email = $self->app->dbi->model('user')->select('email', where => {id => $user})->value; |
|
108 |
my @git_config_user_email = $self->app->git->cmd( |
|
cleanup create working direc...
|
109 |
$work_rep_info, |
improve create working repos...
|
110 |
'config', |
111 |
'user.email', |
|
fix mail bug
|
112 |
"$user_email" |
improve create working repos...
|
113 |
); |
fix mail bug
|
114 |
Gitprep::Util::run_command(@git_config_user_email) |
115 |
or croak "Can't execute git config: @git_config_user_email"; |
|
improve create working repos...
|
116 |
} |
117 |
} |
|
118 | ||
added admin tests
|
119 |
sub admin_user { |
cleanup
|
120 |
my $self = shift; |
121 |
|
|
122 |
# Admin user |
|
123 |
my $admin_user = $self->app->dbi->model('user') |
|
added admin tests
|
124 |
->select(where => {admin => 1})->one; |
cleanup
|
125 |
|
126 |
return $admin_user; |
|
127 |
} |
|
128 | ||
fixed tags page paging bug a...
|
129 |
sub default_branch { |
fix project page
|
130 |
my ($self, $user_id, $project_id, $default_branch) = @_; |
131 |
|
|
132 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
133 |
|
added default branch change ...
|
134 |
# Set default branch |
135 |
my $dbi = $self->app->dbi; |
|
136 |
if (defined $default_branch) { |
|
137 |
$dbi->model('project')->update( |
|
138 |
{default_branch => $default_branch}, |
|
fix project page
|
139 |
where => {user => $user_row_id, id => $project_id} |
added default branch change ...
|
140 |
); |
141 |
} |
|
142 |
else { |
|
143 |
# Get default branch |
|
144 |
my $default_branch = $dbi->model('project') |
|
fix project page
|
145 |
->select('default_branch', where => {user => $user_row_id, id => $project_id}) |
added default branch change ...
|
146 |
->value; |
147 |
|
|
148 |
return $default_branch; |
|
149 |
} |
|
fixed tags page paging bug a...
|
150 |
} |
151 | ||
show deleted repository in u...
|
152 |
sub fork_project { |
fix fork
|
153 |
my ($self, $user_id, $original_user_id, $project_id) = @_; |
154 |
|
|
155 |
my $original_user_row_id = $self->api->get_user_row_id($original_user_id); |
|
show deleted repository in u...
|
156 |
|
157 |
# Fork project |
|
158 |
my $dbi = $self->app->dbi; |
|
159 |
my $error; |
|
160 |
eval { |
|
161 |
$dbi->connector->txn(sub { |
|
162 |
|
|
163 |
# Original project id |
|
fix fork
|
164 |
my $project = $dbi->model('project')->select( |
165 |
['row_id', 'private'], |
|
166 |
where => {user => $original_user_row_id, id => $project_id} |
|
version up and add descripti...
|
167 |
)->one; |
168 |
|
|
fix fork
|
169 |
use D;d [$original_user_row_id, $project_id, $project]; |
show deleted repository in u...
|
170 |
|
171 |
# Create project |
|
172 |
eval { |
|
173 |
$self->_create_project( |
|
fix fork
|
174 |
$user_id, |
175 |
$project_id, |
|
show deleted repository in u...
|
176 |
{ |
fix fork
|
177 |
original_project => $project->{row_id}, |
178 |
private => $project->{private} |
|
show deleted repository in u...
|
179 |
} |
180 |
); |
|
181 |
}; |
|
182 |
croak $error = $@ if $@; |
|
183 |
|
|
184 |
# Create repository |
|
185 |
eval { |
|
fix fork
|
186 |
$self->_fork_rep($original_user_id, $project_id, $user_id, $project_id); |
show deleted repository in u...
|
187 |
}; |
188 |
croak $error = $@ if $@; |
|
189 |
}); |
|
190 |
}; |
|
191 |
croak $error if $@; |
|
192 |
} |
|
193 | ||
cleanup
|
194 |
sub is_admin { |
fix project page
|
195 |
my ($self, $user_id) = @_; |
cleanup
|
196 |
|
197 |
# Check admin |
|
198 |
my $is_admin = $self->app->dbi->model('user') |
|
fix project page
|
199 |
->select('admin', where => {id => $user_id})->value; |
cleanup
|
200 |
|
201 |
return $is_admin; |
|
202 |
} |
|
203 | ||
add private checkbox
|
204 |
sub is_private_project { |
fix project page
|
205 |
my ($self, $user_id, $project_id) = @_; |
206 |
|
|
207 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
add private checkbox
|
208 |
|
209 |
# Is private |
|
fix setting page
|
210 |
my $private = $self->app->dbi->model('project')->select( |
211 |
'private', where => {user => $user_row_id, id => $project_id} |
|
212 |
)->value; |
|
add private checkbox
|
213 |
|
214 |
return $private; |
|
215 |
} |
|
216 | ||
fix project page
|
217 |
sub api { shift->app->gitprep_api } |
218 | ||
219 | ||
fix network page
|
220 |
sub member_projects { |
fix project page
|
221 |
my ($self, $user_id, $project_id) = @_; |
222 |
|
|
223 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
224 |
|
225 |
# DBI |
|
226 |
my $dbi = $self->app->dbi; |
|
227 |
|
|
228 |
# Original project id |
|
fix network page
|
229 |
my $project_row_id = $dbi->model('project') |
230 |
->select('row_id', where => {user => $user_row_id, id => $project_id})->value; |
|
fixed tags page paging bug a...
|
231 |
|
232 |
# Members |
|
233 |
my $members = $dbi->model('project')->select( |
|
fix project page
|
234 |
[ |
fix network page
|
235 |
{__MY__ => ['id']}, |
fix project page
|
236 |
{user => ['id']} |
237 |
], |
|
fix network page
|
238 |
where => { |
239 |
original_project => $project_row_id, |
|
240 |
}, |
|
241 |
append => 'order by user.id, project.id' |
|
fixed tags page paging bug a...
|
242 |
)->all; |
243 | ||
244 |
return $members; |
|
245 |
} |
|
246 | ||
247 |
sub create_project { |
|
fix fork
|
248 |
my ($self, $user_id, $project_id, $opts) = @_; |
fixed tags page paging bug a...
|
249 |
|
add private checkbox to new ...
|
250 |
my $params = {}; |
251 |
if ($opts->{private}) { |
|
252 |
$params->{private} = 1; |
|
253 |
} |
|
254 |
|
|
fixed tags page paging bug a...
|
255 |
# Create project |
fixed bug that setting page ...
|
256 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
257 |
my $error; |
258 |
eval { |
|
259 |
$dbi->connector->txn(sub { |
|
fix fork
|
260 |
eval { $self->_create_project($user_id, $project_id, $params) }; |
fixed tags page paging bug a...
|
261 |
croak $error = $@ if $@; |
fix fork
|
262 |
eval {$self->_create_rep($user_id, $project_id, $opts) }; |
fixed tags page paging bug a...
|
263 |
croak $error = $@ if $@; |
264 |
}); |
|
265 |
}; |
|
266 |
croak $error if $@; |
|
267 |
} |
|
268 | ||
269 |
sub create_user { |
|
270 |
my ($self, $user, $data) = @_; |
|
271 | ||
272 |
# Create user |
|
fixed bug that setting page ...
|
273 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
274 |
my $error; |
275 |
eval { |
|
276 |
$dbi->connector->txn(sub { |
|
277 |
eval { $self->_create_db_user($user, $data) }; |
|
278 |
croak $error = $@ if $@; |
|
279 |
eval {$self->_create_user_dir($user) }; |
|
280 |
croak $error = $@ if $@; |
|
281 |
}); |
|
282 |
}; |
|
283 |
croak $error if $@; |
|
284 |
} |
|
285 | ||
286 |
sub delete_project { |
|
287 |
my ($self, $user, $project) = @_; |
|
288 |
|
|
289 |
# Delete project |
|
fixed bug that setting page ...
|
290 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
291 |
my $error; |
292 |
eval { |
|
293 |
$dbi->connector->txn(sub { |
|
294 |
eval { $self->_delete_project($user, $project) }; |
|
295 |
croak $error = $@ if $@; |
|
296 |
eval {$self->_delete_rep($user, $project) }; |
|
297 |
croak $error = $@ if $@; |
|
298 |
}); |
|
299 |
}; |
|
300 |
croak $error if $@; |
|
301 |
} |
|
302 | ||
303 |
sub delete_user { |
|
304 |
my ($self, $user) = @_; |
|
305 |
|
|
306 |
# Delete user |
|
fixed bug that setting page ...
|
307 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
308 |
my $error; |
added delete user test
|
309 |
my $count; |
fixed tags page paging bug a...
|
310 |
eval { |
311 |
$dbi->connector->txn(sub { |
|
added delete user test
|
312 |
eval { $count = $self->_delete_db_user($user) }; |
fixed tags page paging bug a...
|
313 |
croak $error = $@ if $@; |
314 |
eval {$self->_delete_user_dir($user) }; |
|
315 |
croak $error = $@ if $@; |
|
316 |
}); |
|
317 |
}; |
|
318 |
croak $error if $@; |
|
added delete user test
|
319 |
|
320 |
return $count; |
|
fixed tags page paging bug a...
|
321 |
} |
322 | ||
323 |
sub original_project { |
|
fix project page
|
324 |
my ($self, $user_id, $project_id) = @_; |
325 |
|
|
326 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
327 |
|
cleanup delete original_proj...
|
328 |
# Original project id |
329 |
my $dbi = $self->app->dbi; |
|
fix project page
|
330 |
my $original_project_row_id = $dbi->model('project')->select( |
331 |
'original_project', |
|
332 |
where => {user => $user_row_id, id => $project_id} |
|
333 |
)->value; |
|
cleanup delete original_proj...
|
334 |
|
fix project page
|
335 |
croak "Original project don't eixsts." unless defined $original_project_row_id; |
cleanup delete original_proj...
|
336 |
|
fixed bug that setting page ...
|
337 |
# Original project |
fix some tests
|
338 |
$DB::single = 1 if $main::x; |
cleanup delete original_proj...
|
339 |
my $original_project = $dbi->model('project')->select( |
fix project page
|
340 |
[ |
341 |
{__MY__ => '*'}, |
|
342 |
{user => ['id']} |
|
343 |
], |
|
cleanup delete original_proj...
|
344 |
where => { |
fix project page
|
345 |
'project.row_id' => $original_project_row_id |
cleanup delete original_proj...
|
346 |
} |
fix project page
|
347 |
)->one; |
cleanup delete original_proj...
|
348 |
|
fix project page
|
349 |
return unless defined $original_project; |
fixed tags page paging bug a...
|
350 |
|
351 |
return $original_project; |
|
352 |
} |
|
353 | ||
show deleted repository in u...
|
354 |
sub projects { |
fix user page
|
355 |
my ($self, $user_id) = @_; |
356 |
|
|
357 |
my $user_row_id = $self->app->dbi->model('user')->select('row_id', where => {id => $user_id})->value; |
|
358 |
|
|
show deleted repository in u...
|
359 |
# Projects |
360 |
my $projects = $self->app->dbi->model('project')->select( |
|
fix user page
|
361 |
where => {user => $user_row_id}, |
362 |
append => 'order by id' |
|
show deleted repository in u...
|
363 |
)->all; |
364 |
|
|
365 |
return $projects; |
|
366 |
} |
|
367 | ||
cleanup
|
368 |
sub users { |
369 |
my $self = shift; |
|
fixed bug that setting page ...
|
370 |
|
371 |
# Users |
|
cleanup
|
372 |
my $users = $self->app->dbi->model('user')->select( |
373 |
where => [':admin{<>}',{admin => 1}], |
|
374 |
append => 'order by id' |
|
375 |
)->all; |
|
376 |
|
|
377 |
return $users; |
|
378 |
} |
|
379 | ||
fixed tags page paging bug a...
|
380 |
sub rename_project { |
show deleted repository in u...
|
381 |
my ($self, $user, $project, $to_project) = @_; |
fixed tags page paging bug a...
|
382 |
|
show deleted repository in u...
|
383 |
# Rename project |
revert encoding support
|
384 |
my $git = $self->app->git; |
fixed tags page paging bug a...
|
385 |
my $dbi = $self->app->dbi; |
simplify rename project
|
386 |
my $error; |
387 |
eval { |
|
fixed tags page paging bug a...
|
388 |
$dbi->connector->txn(sub { |
simplify rename project
|
389 |
eval { $self->_rename_project($user, $project, $to_project) }; |
390 |
croak $error = $@ if $@; |
|
391 |
eval { $self->_rename_rep($user, $project, $to_project) }; |
|
392 |
croak $error = $@ if $@; |
|
fixed tags page paging bug a...
|
393 |
}); |
simplify rename project
|
394 |
}; |
395 |
croak $error if $error; |
|
fixed tags page paging bug a...
|
396 |
} |
397 | ||
add key delete feature and u...
|
398 |
sub update_authorized_keys_file { |
399 |
my $self = shift; |
|
400 | ||
401 |
my $authorized_keys_file = $self->authorized_keys_file; |
|
402 |
if (defined $authorized_keys_file) { |
|
403 |
|
|
404 |
# Lock file |
|
fix update_authorized_keys_f...
|
405 |
my $lock_file = $self->app->home->rel_file('lock/authorized_keys'); |
add key delete feature and u...
|
406 |
open my $lock_fh, $lock_file |
407 |
or croak "Can't open lock file $lock_file"; |
|
408 |
flock $lock_fh, LOCK_EX |
|
409 |
or croak "Can't lock $lock_file"; |
|
410 |
|
|
411 |
# Create authorized_keys_file |
|
412 |
unless (-f $authorized_keys_file) { |
|
413 |
open my $fh, '>', $authorized_keys_file |
|
fix gitprep-shell
|
414 |
or croak "Can't create authorized_keys file: $authorized_keys_file"; |
415 |
chmod 0600, $authorized_keys_file |
|
416 |
or croak "Can't chmod authorized_keys file: $authorized_keys_file"; |
|
add key delete feature and u...
|
417 |
} |
418 |
|
|
419 |
# Parse file |
|
forbidden public key which i...
|
420 |
my $result = $self->parse_authorized_keys_file($authorized_keys_file); |
fix update_authorized_keys_f...
|
421 |
my $before_part = $result->{before_part}; |
422 |
my $gitprep_part = $result->{gitprep_part}; |
|
423 |
my $after_part = $result->{after_part}; |
|
424 |
my $start_symbol = $result->{start_symbol}; |
|
425 |
my $end_symbol = $result->{end_symbol}; |
|
add key delete feature and u...
|
426 |
|
427 |
# Backup at first time |
|
428 |
if ($gitprep_part eq '') { |
|
429 |
# Backup original file |
|
430 |
my $to = "$authorized_keys_file.gitprep.original"; |
|
431 |
unless (-f $to) { |
|
432 |
copy $authorized_keys_file, $to |
|
433 |
or croak "Can't copy $authorized_keys_file to $to"; |
|
434 |
} |
|
435 |
} |
|
fix update_authorized_keys_f...
|
436 | |
add key delete feature and u...
|
437 |
# Create public keys |
fix update_authorized_keys_f...
|
438 |
my $ssh_public_keys = $self->app->dbi->model('ssh_public_key')->select->all; |
add key delete feature and u...
|
439 |
my $ssh_public_keys_str = ''; |
440 |
for my $key (@$ssh_public_keys) { |
|
fix permission bug
|
441 |
my $ssh_public_key_str = 'command="' . $self->app->home->rel_file('script/gitprep-shell') |
442 |
. " $key->{user_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $key->{key}"; |
|
fix update_authorized_keys_f...
|
443 |
$ssh_public_keys_str .= "$ssh_public_key_str $key->{user_id}\n\n"; |
add key delete feature and u...
|
444 |
} |
445 |
|
|
446 |
# Output tmp file |
|
fix gitprep-shell
|
447 |
my $output = "$before_part$start_symbol\n\n$ssh_public_keys_str$end_symbol$after_part"; |
add key delete feature and u...
|
448 |
my $output_file = "$authorized_keys_file.gitprep.tmp"; |
449 |
open my $out_fh, '>', $output_file |
|
450 |
or croak "Can't create authorized_keys tmp file $output_file"; |
|
451 |
print $out_fh $output; |
|
452 |
close $out_fh |
|
453 |
or croak "Can't close authorized_keys tmp file $output_file"; |
|
fix update_authorized_keys_f...
|
454 | |
add key delete feature and u...
|
455 |
# Replace |
fix permission bug
|
456 |
chmod 0600, $output_file |
457 |
or croak "Can't chmod authorized_keys tmp file: $output_file"; |
|
add key delete feature and u...
|
458 |
move $output_file, $authorized_keys_file |
459 |
or croak "Can't replace $authorized_keys_file by $output_file"; |
|
460 |
} |
|
461 |
else { |
|
462 |
croak qq/authorized_keys file "$authorized_keys_file" is not found./; |
|
463 |
} |
|
464 |
} |
|
465 | ||
forbidden public key which i...
|
466 |
sub parse_authorized_keys_file { |
fix update_authorized_keys_f...
|
467 |
my ($self, $file) = @_; |
add key delete feature and u...
|
468 |
|
469 |
my $start_symbol = "# gitprep start"; |
|
470 |
my $end_symbol = "# gitprep end"; |
|
471 |
|
|
472 |
# Parse |
|
473 |
open my $fh, '<', $file |
|
fix update_authorized_keys_f...
|
474 |
or croak "Can't open authorized_key file $file"; |
add key delete feature and u...
|
475 |
my $start_symbol_count = 0; |
476 |
my $end_symbol_count = 0; |
|
477 |
my $before_part = ''; |
|
478 |
my $gitprep_part = ''; |
|
479 |
my $after_part = ''; |
|
480 |
my $error_prefix = "authorized_keys file $file format error:"; |
|
481 |
while (my $line = <$fh>) { |
|
482 |
if ($line =~ /^$start_symbol/) { |
|
483 |
if ($start_symbol_count > 0) { |
|
484 |
croak qq/$error_prefix "$start_symbol" is found more than one/; |
|
485 |
} |
|
486 |
else { |
|
487 |
if ($end_symbol_count > 0) { |
|
488 |
croak qq/$error_prefix "$end_symbol" is found before "$start_symbol"/; |
|
489 |
} |
|
490 |
else { |
|
491 |
$start_symbol_count++; |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
elsif ($line =~ /^$end_symbol/) { |
|
fix ssh key authentication b...
|
496 |
if ($end_symbol_count > 0) { |
add key delete feature and u...
|
497 |
croak qq/$error_prefix "$end_symbol" is found more than one/; |
498 |
} |
|
499 |
else { |
|
fix gitprep-shell
|
500 |
$end_symbol_count++; |
add key delete feature and u...
|
501 |
} |
502 |
} |
|
503 |
elsif ($start_symbol_count == 0 && $end_symbol_count == 0) { |
|
504 |
$before_part .= $line; |
|
505 |
} |
|
506 |
elsif ($start_symbol_count == 1 && $end_symbol_count == 0) { |
|
507 |
$gitprep_part .= $line; |
|
508 |
} |
|
509 |
elsif ($start_symbol_count == 1 && $end_symbol_count == 1) { |
|
510 |
$after_part .= $line; |
|
511 |
} |
|
512 |
} |
|
fix update_authorized_keys_f...
|
513 |
|
514 |
my $result = { |
|
515 |
start_symbol => $start_symbol, |
|
516 |
end_symbol => $end_symbol, |
|
517 |
before_part => $before_part, |
|
518 |
gitprep_part => $gitprep_part, |
|
519 |
after_part => $after_part |
|
520 |
}; |
|
521 |
|
|
522 |
return $result; |
|
add key delete feature and u...
|
523 |
} |
524 | ||
fixed tags page paging bug a...
|
525 |
sub _create_project { |
fix fork
|
526 |
my ($self, $user_id, $project_id, $params) = @_; |
527 |
|
|
528 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
529 |
$params ||= {}; |
fix fork
|
530 |
$params->{user} = $user_row_id; |
531 |
$params->{id} = $project_id; |
|
fixed tags page paging bug a...
|
532 |
|
533 |
# Create project |
|
cleanup
|
534 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
535 |
$dbi->connector->txn(sub { |
fix fork
|
536 |
$dbi->model('project')->insert($params); |
fixed tags page paging bug a...
|
537 |
}); |
538 |
} |
|
539 | ||
540 |
sub _create_rep { |
|
541 |
my ($self, $user, $project, $opts) = @_; |
|
542 |
|
|
543 |
# Create repository directory |
|
revert encoding support
|
544 |
my $git = $self->app->git; |
remove rep_path
|
545 |
|
546 |
my $rep_info = $self->app->rep_info($user, $project); |
|
547 |
my $rep_git_dir = $rep_info->{git_dir}; |
|
548 |
|
|
549 |
mkdir $rep_git_dir |
|
550 |
or croak "Can't create directory $rep_git_dir: $!"; |
|
fix bug that in CGI reposito...
|
551 |
|
fixed tags page paging bug a...
|
552 |
eval { |
553 |
# Git init |
|
554 |
{ |
|
remove cmd_dir
|
555 |
my @git_init_cmd = $git->cmd($rep_info, 'init', '--bare'); |
fix bug that in CGI reposito...
|
556 |
Gitprep::Util::run_command(@git_init_cmd) |
fix git 2.0 create repositor...
|
557 |
or croak "Can't execute git init --bare:@git_init_cmd"; |
fixed tags page paging bug a...
|
558 |
} |
559 |
|
|
560 |
# Add git-daemon-export-ok |
|
561 |
{ |
|
remove rep_path
|
562 |
my $file = "$rep_git_dir/git-daemon-export-ok"; |
fixed tags page paging bug a...
|
563 |
open my $fh, '>', $file |
564 |
or croak "Can't create git-daemon-export-ok: $!" |
|
565 |
} |
|
566 |
|
|
567 |
# HTTP support |
|
remove cmd_dir
|
568 |
my @git_update_server_info_cmd = $git->cmd( |
569 |
$rep_info, |
|
fixed tags page paging bug a...
|
570 |
'--bare', |
571 |
'update-server-info' |
|
572 |
); |
|
fix bug that in CGI reposito...
|
573 |
Gitprep::Util::run_command(@git_update_server_info_cmd) |
fix git 2.0 create repositor...
|
574 |
or croak "Can't execute git --bare update-server-info"; |
remove rep_path
|
575 |
move("$rep_git_dir/hooks/post-update.sample", "$rep_git_dir/hooks/post-update") |
fixed tags page paging bug a...
|
576 |
or croak "Can't move post-update"; |
577 |
|
|
578 |
# Description |
|
version up and add descripti...
|
579 |
my $description = $opts->{description}; |
580 |
$description = '' unless defined $description; |
|
fixed tags page paging bug a...
|
581 |
{ |
remove rep_path
|
582 |
my $file = "$rep_git_dir/description"; |
fixed tags page paging bug a...
|
583 |
open my $fh, '>', $file |
584 |
or croak "Can't open $file: $!"; |
|
585 |
print $fh encode('UTF-8', $description) |
|
586 |
or croak "Can't write $file: $!"; |
|
587 |
close $fh; |
|
588 |
} |
|
589 |
|
|
590 |
# Add README and commit |
|
591 |
if ($opts->{readme}) { |
|
592 |
# Create working directory |
|
use own tmp directory to cre...
|
593 |
my $home_tmp_dir = $self->app->home->rel_file('tmp'); |
594 |
|
|
remove cmd_work_dir
|
595 |
# Temp directory |
use own tmp directory to cre...
|
596 |
my $temp_dir = File::Temp->newdir(DIR => $home_tmp_dir); |
remove cmd_work_dir
|
597 |
|
598 |
# Working repository |
|
599 |
my $work_rep_work_tree = "$temp_dir/work"; |
|
600 |
my $work_rep_git_dir = "$work_rep_work_tree/.git"; |
|
601 |
my $work_rep_info = { |
|
602 |
work_tree => $work_rep_work_tree, |
|
603 |
git_dir => $work_rep_git_dir |
|
604 |
}; |
|
605 |
|
|
606 |
mkdir $work_rep_work_tree |
|
607 |
or croak "Can't create directory $work_rep_work_tree: $!"; |
|
use own tmp directory to cre...
|
608 |
|
fixed tags page paging bug a...
|
609 |
# Git init |
remove cmd_work_dir
|
610 |
my @git_init_cmd = $git->cmd($work_rep_info, 'init', '-q'); |
fix bug that in CGI reposito...
|
611 |
Gitprep::Util::run_command(@git_init_cmd) |
fix git 2.0 create repositor...
|
612 |
or croak "Can't execute git init: @git_init_cmd"; |
fixed tags page paging bug a...
|
613 |
|
614 |
# Add README |
|
remove cmd_work_dir
|
615 |
my $file = "$work_rep_work_tree/README.md"; |
default readme file is chang...
|
616 |
open my $readme_fh, '>', $file |
fixed tags page paging bug a...
|
617 |
or croak "Can't create $file: $!"; |
version up and add descripti...
|
618 |
print $readme_fh "# $project\n"; |
619 |
print $readme_fh "\n" . encode('UTF-8', $description) . "\n"; |
|
default readme file is chang...
|
620 |
close $readme_fh; |
621 |
|
|
remove cmd_work_dir
|
622 |
my @git_add_cmd = $git->cmd( |
623 |
$work_rep_info, |
|
fixed tags page paging bug a...
|
624 |
'add', |
default readme file is chang...
|
625 |
'README.md' |
fixed tags page paging bug a...
|
626 |
); |
improve create working repos...
|
627 |
|
fix bug that in CGI reposito...
|
628 |
Gitprep::Util::run_command(@git_add_cmd) |
fix git 2.0 create repositor...
|
629 |
or croak "Can't execute git add: @git_add_cmd"; |
fixed tags page paging bug a...
|
630 |
|
fix bug that repository with...
|
631 |
# Set user name |
remove cmd_work_dir
|
632 |
my @git_config_user_name = $git->cmd( |
633 |
$work_rep_info, |
|
fix bug that repository with...
|
634 |
'config', |
635 |
'user.name', |
|
636 |
$user |
|
637 |
); |
|
638 |
Gitprep::Util::run_command(@git_config_user_name) |
|
639 |
or croak "Can't execute git config: @git_config_user_name"; |
|
640 |
|
|
fix mail bug
|
641 |
# Set user email |
642 |
my $user_email = $self->app->dbi->model('user')->select('email', where => {id => $user})->value; |
|
643 |
my @git_config_user_email = $git->cmd( |
|
remove cmd_work_dir
|
644 |
$work_rep_info, |
fix bug that repository with...
|
645 |
'config', |
646 |
'user.email', |
|
fix mail bug
|
647 |
"$user_email" |
fix bug that repository with...
|
648 |
); |
fix mail bug
|
649 |
Gitprep::Util::run_command(@git_config_user_email) |
650 |
or croak "Can't execute git config: @git_config_user_email"; |
|
fix bug that repository with...
|
651 |
|
fixed tags page paging bug a...
|
652 |
# Commit |
remove cmd_work_dir
|
653 |
my @git_commit_cmd = $git->cmd( |
654 |
$work_rep_info, |
|
fixed tags page paging bug a...
|
655 |
'commit', |
656 |
'-q', |
|
657 |
'-m', |
|
658 |
'first commit' |
|
659 |
); |
|
fix bug that in CGI reposito...
|
660 |
Gitprep::Util::run_command(@git_commit_cmd) |
fix git 2.0 create repositor...
|
661 |
or croak "Can't execute git commit: @git_commit_cmd"; |
fixed tags page paging bug a...
|
662 |
|
663 |
# Push |
|
664 |
{ |
|
remove cmd_work_dir
|
665 |
my @git_push_cmd = $git->cmd( |
666 |
$work_rep_info, |
|
fixed tags page paging bug a...
|
667 |
'push', |
668 |
'-q', |
|
remove rep_path
|
669 |
$rep_git_dir, |
fixed tags page paging bug a...
|
670 |
'master' |
671 |
); |
|
672 |
# (This is bad, but --quiet option can't supress in old git) |
|
fix bug that in CGI reposito...
|
673 |
Gitprep::Util::run_command(@git_push_cmd) |
fix git 2.0 create repositor...
|
674 |
or croak "Can't execute git push: @git_push_cmd"; |
fixed tags page paging bug a...
|
675 |
} |
676 |
} |
|
677 |
}; |
|
improve faq of pushing lerge...
|
678 |
if (my $e = $@) { |
remove rep_path
|
679 |
rmtree $rep_git_dir; |
improve faq of pushing lerge...
|
680 |
croak $e; |
fixed tags page paging bug a...
|
681 |
} |
682 |
} |
|
683 | ||
show deleted repository in u...
|
684 |
sub _create_db_user { |
fix project page
|
685 |
my ($self, $user_id, $data) = @_; |
686 |
|
|
687 |
$data->{id} = $user_id; |
|
show deleted repository in u...
|
688 |
|
689 |
# Create database user |
|
fix project page
|
690 |
$self->app->dbi->model('user')->insert($data); |
show deleted repository in u...
|
691 |
} |
692 | ||
693 |
sub _create_user_dir { |
|
694 |
my ($self, $user) = @_; |
|
695 |
|
|
696 |
# Create user directory |
|
cleanup ->rep_home
|
697 |
my $rep_home = $self->app->rep_home; |
show deleted repository in u...
|
698 |
my $user_dir = "$rep_home/$user"; |
699 |
mkpath $user_dir; |
|
700 |
} |
|
701 | ||
702 |
sub _delete_db_user { |
|
fix project page
|
703 |
my ($self, $user_id) = @_; |
show deleted repository in u...
|
704 |
|
705 |
# Delete database user |
|
fix project page
|
706 |
my $count = $self->app->dbi->model('user')->delete(where => {id => $user_id}); |
added delete user test
|
707 |
|
708 |
return $count; |
|
show deleted repository in u...
|
709 |
} |
710 | ||
711 |
sub _delete_user_dir { |
|
712 |
my ($self, $user) = @_; |
|
713 |
|
|
714 |
# Delete user directory |
|
cleanup ->rep_home
|
715 |
my $rep_home = $self->app->rep_home; |
show deleted repository in u...
|
716 |
my $user_dir = "$rep_home/$user"; |
717 |
rmtree $user_dir; |
|
718 |
} |
|
719 | ||
fixed tags page paging bug a...
|
720 |
sub _delete_project { |
fix project page
|
721 |
my ($self, $user_id, $project_id) = @_; |
722 |
|
|
723 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
724 |
|
cleanup
|
725 |
# Delete project |
fixed tags page paging bug a...
|
726 |
my $dbi = $self->app->dbi; |
fix project page
|
727 |
$dbi->model('project')->delete(where => {user => $user_row_id, id => $project_id}); |
fixed tags page paging bug a...
|
728 |
} |
729 | ||
730 |
sub _delete_rep { |
|
731 |
my ($self, $user, $project) = @_; |
|
732 | ||
cleanup
|
733 |
# Delete repository |
cleanup ->rep_home
|
734 |
my $rep_home = $self->app->rep_home; |
add missing 'o'
|
735 |
croak "Can't remove repository. repository home is empty" |
fixed tags page paging bug a...
|
736 |
if !defined $rep_home || $rep_home eq ''; |
737 |
my $rep = "$rep_home/$user/$project.git"; |
|
738 |
rmtree $rep; |
|
739 |
croak "Can't remove repository. repository is rest" |
|
740 |
if -e $rep; |
|
741 |
} |
|
742 | ||
fixed bug that setting page ...
|
743 |
sub exists_project { |
fix project page
|
744 |
my ($self, $user_id, $project_id) = @_; |
745 |
|
|
746 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
cleanup
|
747 |
|
748 |
# Exists project |
|
fixed tags page paging bug a...
|
749 |
my $dbi = $self->app->dbi; |
fix project page
|
750 |
my $row = $dbi->model('project')->select(where => {user => $user_row_id, id => $project_id})->one; |
fixed tags page paging bug a...
|
751 |
|
752 |
return $row ? 1 : 0; |
|
753 |
} |
|
754 | ||
add rename project and suppr...
|
755 |
sub exists_user { |
fix project page
|
756 |
my ($self, $user_id) = @_; |
add rename project and suppr...
|
757 |
|
758 |
# Exists project |
|
fix project page
|
759 |
my $row = $self->app->dbi->model('user')->select(where => {id => $user_id})->one; |
add rename project and suppr...
|
760 |
|
761 |
return $row ? 1 : 0; |
|
762 |
} |
|
763 | ||
fixed tags page paging bug a...
|
764 |
sub _exists_rep { |
765 |
my ($self, $user, $project) = @_; |
|
766 |
|
|
cleanup
|
767 |
# Exists repository |
remove rep_path
|
768 |
my $rep_info = $self->app->rep_info($user, $project); |
769 |
my $rep_git_dir = $rep_info->{git_dir}; |
|
fixed tags page paging bug a...
|
770 |
|
remove rep_path
|
771 |
return -e $rep_git_dir; |
fixed tags page paging bug a...
|
772 |
} |
773 | ||
show deleted repository in u...
|
774 |
sub _fork_rep { |
fix fork
|
775 |
my ($self, $user_id, $project_id, $to_user_id, $to_project_id) = @_; |
show deleted repository in u...
|
776 |
|
cleanup
|
777 |
# Fork repository |
revert encoding support
|
778 |
my $git = $self->app->git; |
remove rep_path
|
779 |
|
fix fork
|
780 |
my $rep_info = $self->app->rep_info($user_id, $project_id); |
remove rep_path
|
781 |
my $rep_git_dir = $rep_info->{git_dir}; |
782 |
|
|
fix fork
|
783 |
my $to_rep_info = $self->app->rep_info($to_user_id, $to_project_id); |
remove rep_path
|
784 |
my $to_rep_git_dir = $to_rep_info->{git_dir}; |
785 | ||
show deleted repository in u...
|
786 |
my @cmd = ( |
787 |
$git->bin, |
|
788 |
'clone', |
|
789 |
'-q', |
|
790 |
'--bare', |
|
remove rep_path
|
791 |
$rep_git_dir, |
792 |
$to_rep_git_dir |
|
show deleted repository in u...
|
793 |
); |
fix bug that in CGI reposito...
|
794 |
Gitprep::Util::run_command(@cmd) |
fix description file not cop...
|
795 |
or croak "Can't fork repository(_fork_rep): @cmd"; |
796 |
|
|
797 |
# Copy description |
|
remove rep_path
|
798 |
copy "$rep_git_dir/description", "$to_rep_git_dir/description" |
fix description file not cop...
|
799 |
or croak "Can't copy description file(_fork_rep)"; |
show deleted repository in u...
|
800 |
} |
801 | ||
fixed tags page paging bug a...
|
802 |
sub _rename_project { |
fix project page
|
803 |
my ($self, $user_id, $project_id, $renamed_project_id) = @_; |
804 |
|
|
805 |
my $user_row_id = $self->api->get_user_row_id($user_id); |
|
fixed tags page paging bug a...
|
806 |
|
cleanup
|
807 |
# Check arguments |
add rename project and suppr...
|
808 |
croak "Invalid parameters(_rename_project)" |
fix project page
|
809 |
unless defined $user_id && defined $project_id && defined $renamed_project_id; |
fixed tags page paging bug a...
|
810 |
|
811 |
# Rename project |
|
cleanup
|
812 |
my $dbi = $self->app->dbi; |
fixed tags page paging bug a...
|
813 |
$dbi->model('project')->update( |
fix project page
|
814 |
{id => $renamed_project_id}, |
815 |
where => {user => $user_row_id, id => $project_id} |
|
fixed tags page paging bug a...
|
816 |
); |
817 |
} |
|
818 | ||
819 |
sub _rename_rep { |
|
820 |
my ($self, $user, $project, $renamed_project) = @_; |
|
821 |
|
|
cleanup
|
822 |
# Check arguments |
fixed tags page paging bug a...
|
823 |
croak "Invalid user name or project" |
824 |
unless defined $user && defined $project && defined $renamed_project; |
|
cleanup
|
825 | |
826 |
# Rename repository |
|
remove rep_path
|
827 |
my $rep_info = $self->app->rep_info($user, $project); |
828 |
my $rep_git_dir = $rep_info->{git_dir}; |
|
829 |
|
|
830 |
my $renamed_rep_info = $self->app->rep_info($user, $renamed_project); |
|
831 |
my $renamed_rep_git_dir = $renamed_rep_info->{git_dir}; |
|
832 | ||
833 |
move($rep_git_dir, $renamed_rep_git_dir) |
|
834 |
or croak "Can't move $rep_git_dir to $renamed_rep_git_dir: $!"; |
|
fixed tags page paging bug a...
|
835 |
} |
836 | ||
837 |
1; |