gitprep / lib / Gitprep / Manager.pm /
Newer Older
1054 lines | 27.207kb
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1
package Gitprep::Manager;
2
use Mojo::Base -base;
3

            
4
use Carp 'croak';
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
5
use Encode 'encode';
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
6
use File::Copy qw/move copy/;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
7
use File::Path qw/mkpath rmtree/;
8
use File::Temp ();
add key delete feature and u...
gitprep authored on 2014-05-19
9
use Fcntl ':flock';
10
use Carp 'croak';
11
use File::Copy qw/copy move/;
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
12
use File::Spec;
13
use Gitprep::Util;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
14

            
15
has 'app';
add key delete feature and u...
gitprep authored on 2014-05-19
16
has 'authorized_keys_file';
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
17

            
add lock system
Yuki Kimoto authored on 2016-04-18
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...
Yuki Kimoto authored on 2016-04-18
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
Yuki Kimoto authored on 2016-04-16
67
sub create_work_rep {
improve create working repos...
Yuki Kimoto authored on 2016-04-15
68
  my ($self, $user, $project) = @_;
69
  
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
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...
Yuki Kimoto authored on 2016-04-15
78
  # Create working repository if it don't exist
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
79
  unless (-e $work_tree) {
80

            
improve create working repos...
Yuki Kimoto authored on 2016-04-15
81
    # git clone
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
82
    my @git_clone_cmd = ($self->app->git->bin, 'clone', $rep_git_dir, $work_tree);
improve create working repos...
Yuki Kimoto authored on 2016-04-15
83
    Gitprep::Util::run_command(@git_clone_cmd)
84
      or croak "Can't git clone: @git_clone_cmd";
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
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...
Yuki Kimoto authored on 2016-04-15
95

            
96
    # Set user name
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
97
    my @git_config_user_name = $self->app->git->cmd(
98
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
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
    
106
    # Set user mail
107
    my $user_mail = $self->app->dbi->model('user')->select('mail', where => {id => $user})->value;
cleanup create working direc...
Yuki Kimoto authored on 2016-04-16
108
    my @git_config_user_mail = $self->app->git->cmd(
109
      $work_rep_info,
improve create working repos...
Yuki Kimoto authored on 2016-04-15
110
      'config',
111
      'user.email',
112
      "$user_mail"
113
    );
114
    Gitprep::Util::run_command(@git_config_user_mail)
115
      or croak "Can't execute git config: @git_config_user_mail";
116
  }
117
}
118

            
added admin tests
Yuki Kimoto authored on 2013-05-16
119
sub admin_user {
cleanup
Yuki Kimoto authored on 2013-05-13
120
  my $self = shift;
121
  
122
  # Admin user
123
  my $admin_user = $self->app->dbi->model('user')
added admin tests
Yuki Kimoto authored on 2013-05-16
124
    ->select(where => {admin => 1})->one;
cleanup
Yuki Kimoto authored on 2013-05-13
125
  
126
  return $admin_user;
127
}
128

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
129
sub default_branch {
added default branch change ...
Yuki Kimoto authored on 2013-05-22
130
  my ($self, $user, $project, $default_branch) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
131
  
added default branch change ...
Yuki Kimoto authored on 2013-05-22
132
  # Set default branch
133
  my $dbi = $self->app->dbi;
134
  if (defined $default_branch) {
135
    $dbi->model('project')->update(
136
      {default_branch => $default_branch},
137
      id => [$user, $project]
138
    );
139
  }
140
  else {
141
    # Get default branch
142
    my $default_branch = $dbi->model('project')
143
      ->select('default_branch', id => [$user, $project])
144
      ->value;
145
    
146
    return $default_branch;
147
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
148
}
149

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
150
sub fork_project {
151
  my ($self, $user, $original_user, $project) = @_;
152
  
153
  # Fork project
154
  my $dbi = $self->app->dbi;
155
  my $error;
156
  eval {
157
    $dbi->connector->txn(sub {
158
      
159
      # Original project id
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
160
      my $project_info = $dbi->model('project')->select(
161
        ['original_pid', 'private'],
162
        id => [$original_user, $project]
163
      )->one;
164
      
165
      my $original_pid = $project_info->{original_pid};
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
166
      
167
      croak "Can't get original project id"
168
        unless defined $original_pid && $original_pid > 0;
169
      
170
      # Create project
171
      eval {
172
        $self->_create_project(
173
          $user,
174
          $project,
175
          {
176
            original_user => $original_user,
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
177
            original_pid => $original_pid,
178
            private => $project_info->{private}
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
179
          }
180
        );
181
      };
182
      croak $error = $@ if $@;
183
      
184
      # Create repository
185
      eval {
186
        $self->_fork_rep($original_user, $project, $user, $project);
187
      };
188
      croak $error = $@ if $@;
189
    });
190
  };
191
  croak $error if $@;
192
}
193

            
cleanup
Yuki Kimoto authored on 2013-05-13
194
sub is_admin {
195
  my ($self, $user) = @_;
196
  
197
  # Check admin
198
  my $is_admin = $self->app->dbi->model('user')
199
    ->select('admin', id => $user)->value;
200
  
201
  return $is_admin;
202
}
203

            
add private checkbox
Yuki Kimoto authored on 2013-11-16
204
sub is_private_project {
205
  my ($self, $user, $project) = @_;
206
  
207
  # Is private
208
  my $private = $self->app->dbi->model('project')
209
    ->select('private', id => [$user, $project])->value;
210
  
211
  return $private;
212
}
213

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
214
sub members {
215
  my ($self, $user, $project) = @_;
216
  
217
  # DBI
218
  my $dbi = $self->app->dbi;
219
  
220
  # Original project id
221
  my $original_pid = $dbi->model('project')
222
    ->select('original_pid', id => [$user, $project])->value;
223
  
224
  # Members
225
  my $members = $dbi->model('project')->select(
226
    ['user_id as id', 'name as project'],
227
    where => [
228
      ['and',
229
        ':original_pid{=}',
230
        ['or', ':user_id{<>}', ':name{<>}']
231
      ],
232
      {
233
        original_pid => $original_pid,
234
        user_id => $user,
235
        name => $project
236
      }
237
    ],
238
    append => 'order by user_id, name'
239
  )->all;
240

            
241
  return $members;
242
}
243

            
244
sub create_project {
245
  my ($self, $user, $project, $opts) = @_;
246
  
add private checkbox to new ...
Yuki Kimoto authored on 2013-11-26
247
  my $params = {};
248
  if ($opts->{private}) {
249
    $params->{private} = 1;
250
  }
251
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
252
  # Create project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
253
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
254
  my $error;
255
  eval {
256
    $dbi->connector->txn(sub {
add private checkbox to new ...
Yuki Kimoto authored on 2013-11-26
257
      eval { $self->_create_project($user, $project, $params) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
258
      croak $error = $@ if $@;
259
      eval {$self->_create_rep($user, $project, $opts) };
260
      croak $error = $@ if $@;
261
    });
262
  };
263
  croak $error if $@;
264
}
265

            
266
sub create_user {
267
  my ($self, $user, $data) = @_;
268

            
269
  # Create user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
270
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
271
  my $error;
272
  eval {
273
    $dbi->connector->txn(sub {
274
      eval { $self->_create_db_user($user, $data) };
275
      croak $error = $@ if $@;
276
      eval {$self->_create_user_dir($user) };
277
      croak $error = $@ if $@;
278
    });
279
  };
280
  croak $error if $@;
281
}
282

            
283
sub delete_project {
284
  my ($self, $user, $project) = @_;
285
  
286
  # Delete project
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
287
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
288
  my $error;
289
  eval {
290
    $dbi->connector->txn(sub {
291
      eval { $self->_delete_project($user, $project) };
292
      croak $error = $@ if $@;
293
      eval {$self->_delete_rep($user, $project) };
294
      croak $error = $@ if $@;
295
    });
296
  };
297
  croak $error if $@;
298
}
299

            
300
sub delete_user {
301
  my ($self, $user) = @_;
302
  
303
  # Delete user
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
304
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
305
  my $error;
added delete user test
Yuki Kimoto authored on 2013-05-18
306
  my $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
307
  eval {
308
    $dbi->connector->txn(sub {
added delete user test
Yuki Kimoto authored on 2013-05-18
309
      eval { $count = $self->_delete_db_user($user) };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
310
      croak $error = $@ if $@;
311
      eval {$self->_delete_user_dir($user) };
312
      croak $error = $@ if $@;
313
    });
314
  };
315
  croak $error if $@;
added delete user test
Yuki Kimoto authored on 2013-05-18
316
  
317
  return $count;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
318
}
319

            
320
sub original_project {
321
  my ($self, $user, $project) = @_;
322
  
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
323
  # Original project id
324
  my $dbi = $self->app->dbi;
325
  my $row = $dbi->model('project')->select(
326
    ['original_user', 'original_pid'],
327
    id => [$user, $project]
328
  )->one;
329
  
add import branch tests
Yuki Kimoto authored on 2013-08-19
330
  croak "Original project don't eixsts." unless $row;
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
331
  
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
332
  # Original project
cleanup delete original_proj...
Yuki Kimoto authored on 2013-05-26
333
  my $original_project = $dbi->model('project')->select(
334
    'name',
335
    where => {
336
      user_id => $row->{original_user},
337
      original_pid => $row->{original_pid}
338
    }
339
  )->value;
340
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
341
  return unless defined $original_project && length $original_project;
342
  
343
  return $original_project;
344
}
345

            
346
sub original_user {
347
  my ($self, $user, $project) = @_;
348
  
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
349
  # Orginal user
350
  my $original_user = $self->app->dbi->model('project')
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
351
    ->select('original_user', id => [$user, $project])
352
    ->value;
353
  return unless defined $original_user && length $original_user;
354
  
355
  return $original_user;
356
}
357

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
358
sub projects {
359
  my ($self, $user) = @_;
360

            
361
  # Projects
362
  my $projects = $self->app->dbi->model('project')->select(
363
    where => {user_id => $user},
364
    append => 'order by name'
365
  )->all;
366
  
367
  return $projects;
368
}
369

            
cleanup
Yuki Kimoto authored on 2013-05-13
370
sub users {
371
  my $self = shift;
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
372
  
373
  # Users
cleanup
Yuki Kimoto authored on 2013-05-13
374
  my $users = $self->app->dbi->model('user')->select(
375
    where => [':admin{<>}',{admin => 1}],
376
    append => 'order by id'
377
  )->all;
378
  
379
  return $users;
380
}
381

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
382
sub rename_project {
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
383
  my ($self, $user, $project, $to_project) = @_;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
384
  
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
385
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
386
  my $git = $self->app->git;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
387
  my $dbi = $self->app->dbi;
simplify rename project
Yuki Kimoto authored on 2013-05-22
388
  my $error;
389
  eval {
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
390
    $dbi->connector->txn(sub {
simplify rename project
Yuki Kimoto authored on 2013-05-22
391
      eval { $self->_rename_project($user, $project, $to_project) };
392
      croak $error = $@ if $@;
393
      eval { $self->_rename_rep($user, $project, $to_project) };
394
      croak $error = $@ if $@;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
395
    });
simplify rename project
Yuki Kimoto authored on 2013-05-22
396
  };
397
  croak $error if $error;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
398
}
399

            
400
sub setup_database {
401
  my $self = shift;
402
  
403
  my $dbi = $self->app->dbi;
404
  
405
  # Create user table
406
  eval {
407
    my $sql = <<"EOS";
408
create table user (
409
  row_id integer primary key autoincrement,
410
  id not null unique default ''
411
);
412
EOS
413
    $dbi->execute($sql);
414
  };
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
415
  
416
  # Check mail column
417
  my $not_exists_user_mail;
418
  eval { $dbi->select('mail', table => 'user') };
419
  if ($@) {
420
    $not_exists_user_mail = 1;
421
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
422

            
add ssh key add feature
gitprep authored on 2014-05-17
423
  # Create user columns
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
424
  my $user_columns = [
425
    "admin not null default '0'",
426
    "password not null default ''",
add user.name and user.mail
Yuki Kimoto authored on 2016-04-06
427
    "salt not null default ''",
428
    "mail not null default ''",
429
    "name not null default ''"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
430
  ];
431
  for my $column (@$user_columns) {
432
    eval { $dbi->execute("alter table user add column $column") };
433
  }
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
434

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
435
  # Check user table
add user.name and user.mail
Yuki Kimoto authored on 2016-04-06
436
  eval { $dbi->select([qw/row_id id admin password salt mail name/], table => 'user') };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
437
  if ($@) {
438
    my $error = "Can't create user table properly: $@";
439
    $self->app->log->error($error);
440
    croak $error;
441
  }
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
442
  
443
  # If mail is empty, id is copied to mail for uniqueness
444
  my $user_ids = $dbi->select('id', table => 'user', where => {mail => ''})->values;
445
  for my $user_id (@$user_ids) {
446
    $dbi->update({mail => "$user_id\@gitprep.example"}, table => 'user', where => {id => $user_id});
447
  }
448
  
449
  # add unique to mail
450
  eval { $dbi->execute("create unique index user__mail on user(mail)") };
451
  my $created_user_mail_index = $dbi->execute("select * from sqlite_master where type = 'index' and name = 'user__mail'")->one;
452
  unless ($created_user_mail_index) {
453
    croak "Can't create user__mail index";
454
  }
455
  
add ssh key add feature
gitprep authored on 2014-05-17
456
  # Create ssh_public_key table
457
  eval {
458
    my $sql = <<"EOS";
459
create table ssh_public_key (
460
  row_id integer primary key autoincrement,
fix ssh key authentication b...
gitprep authored on 2014-05-20
461
  key not null unique default ''
add ssh key add feature
gitprep authored on 2014-05-17
462
);
463
EOS
464
    $dbi->execute($sql);
465
  };
466

            
467
  # Create ssh_public_key columns
468
  my $ssh_public_key_columns = [
fix ssh key authentication b...
gitprep authored on 2014-05-20
469
    "user_id not null default ''",
470
    "title not null default ''"
add ssh key add feature
gitprep authored on 2014-05-17
471
  ];
472
  for my $column (@$ssh_public_key_columns) {
473
    eval { $dbi->execute("alter table ssh_public_key add column $column") };
474
  }
475
  
476
  # Check ssh_public_key table
477
  eval { $dbi->select([qw/row_id user_id key title/], table => 'ssh_public_key') };
478
  if ($@) {
479
    my $error = "Can't create ssh_public_key table properly: $@";
480
    $self->app->log->error($error);
481
    croak $error;
482
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
483
  
484
  # Create project table
485
  eval {
486
    my $sql = <<"EOS";
487
create table project (
488
  row_id integer primary key autoincrement,
489
  user_id not null,
490
  name not null,
491
  unique(user_id, name)
492
);
493
EOS
494
    $dbi->execute($sql);
495
  };
496
  
497
  # Create Project columns
498
  my $project_columns = [
499
    "default_branch not null default 'master'",
500
    "original_user not null default ''",
add private checkbox
Yuki Kimoto authored on 2013-11-16
501
    "original_pid integer not null default 0",
remove [basic]show_ignore_sp...
Yuki Kimoto authored on 2016-04-02
502
    "private not null default 0",
add guess_encoding column an...
Yuki Kimoto authored on 2016-04-05
503
    "ignore_space_change not null default 0",
504
    "guess_encoding not null default ''"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
505
  ];
506
  for my $column (@$project_columns) {
507
    eval { $dbi->execute("alter table project add column $column") };
508
  }
509

            
510
  # Check project table
add guess_encoding column an...
Yuki Kimoto authored on 2016-04-05
511
  eval {
512
    $dbi->select(
513
      [qw/default_branch original_user original_pid private ignore_space_change guess_encoding/],
514
      table => 'project'
515
    );
516
  };
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
517
  if ($@) {
518
    my $error = "Can't create project table properly: $@";
519
    $self->app->log->error($error);
520
    croak $error;
521
  }
522

            
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
523
  # Create collaboration table
524
  eval {
525
    my $sql = <<"EOS";
526
create table collaboration (
527
  row_id integer primary key autoincrement,
fix bug that can't create co...
Yuki Kimoto authored on 2014-03-08
528
  user_id not null default '',
529
  project_name not null default '',
530
  collaborator_id not null default '',
add collaborator register lo...
Yuki Kimoto authored on 2013-11-17
531
  unique(user_id, project_name, collaborator_id)
532
);
533
EOS
534
    $dbi->execute($sql);
535
  };
536
  
537
  # Check collaboration table
538
  eval { $dbi->select([qw/row_id user_id project_name collaborator_id/], table => 'collaboration') };
539
  if ($@) {
540
    my $error = "Can't create collaboration table properly: $@";
541
    $self->app->log->error($error);
542
    croak $error;
543
  }
544

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
545
  # Create number table
546
  eval {
547
    my $sql = <<"EOS";
548
create table number (
549
  row_id integer primary key autoincrement,
550
  key not null unique
551
);
552
EOS
553
    $dbi->execute($sql);
554
  };
555
  
556
  # Create number columns
557
  my $number_columns = [
558
    "value integer not null default '0'"
559
  ];
560
  for my $column (@$number_columns) {
561
    eval { $dbi->execute("alter table number add column $column") };
562
  }
563

            
564
  # Check number table
565
  eval { $dbi->select([qw/row_id key value/], table => 'number') };
566
  if ($@) {
567
    my $error = "Can't create number table properly: $@";
568
    $self->app->log->error($error);
569
    croak $error;
570
  }
571
  
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
572
  # Original project id number
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
573
  eval { $dbi->insert({key => 'original_pid'}, table => 'number') };
574
  my $original_pid = $dbi->select(
575
    'key',
576
    table => 'number',
577
    where => {key => 'original_pid'}
578
  )->value;
579
  unless (defined $original_pid) {
580
    my $error = "Can't create original_pid row in number table";
581
    $self->app->log->error($error);
582
    croak $error;
583
  }
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
584

            
585
  # Create pull_request table
586
  eval {
587
    my $sql = <<"EOS";
588
create table pull_request (
589
  row_id integer primary key autoincrement,
590
  project integer not null default 0,
591
  branch1 not null default '',
592
  branch2 not null default '',
593
  unique(project, branch1, branch2)
594
);
595
EOS
596
    $dbi->execute($sql);
597
  };
598
  
599
  # Create pull_request columns
600
  my @pull_request_columns = (
601
    "title not null default ''",
create pull request list
Yuki Kimoto authored on 2016-04-20
602
    "message not null default ''",
603
    "open integer default 0",
604
    "open_time integer default 0'",
605
    "open_user integer default 0"
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
606
  );
607
  for my $column (@pull_request_columns) {
608
    eval { $dbi->execute("alter table pull_request add column $column") };
609
  }
610

            
611
  # Check pull_request table
create pull request list
Yuki Kimoto authored on 2016-04-20
612
  eval { $dbi->select([qw/row_id project branch1 branch2 title message open/], table => 'pull_request') };
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
613
  if ($@) {
614
    my $error = "Can't create pull_request table properly: $@";
615
    $self->app->log->error($error);
616
    croak $error;
617
  }
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
618
}
619

            
add key delete feature and u...
gitprep authored on 2014-05-19
620

            
621
sub update_authorized_keys_file {
622
  my $self = shift;
623

            
624
  my $authorized_keys_file = $self->authorized_keys_file;
625
  if (defined $authorized_keys_file) {
626
    
627
    # Lock file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
628
    my $lock_file = $self->app->home->rel_file('lock/authorized_keys');
add key delete feature and u...
gitprep authored on 2014-05-19
629
    open my $lock_fh, $lock_file
630
      or croak "Can't open lock file $lock_file";
631
    flock $lock_fh, LOCK_EX
632
      or croak "Can't lock $lock_file";
633
    
634
    # Create authorized_keys_file
635
    unless (-f $authorized_keys_file) {
636
      open my $fh, '>', $authorized_keys_file
fix gitprep-shell
gitprep authored on 2014-05-19
637
        or croak "Can't create authorized_keys file: $authorized_keys_file";
638
      chmod 0600, $authorized_keys_file
639
        or croak "Can't chmod authorized_keys file: $authorized_keys_file";
add key delete feature and u...
gitprep authored on 2014-05-19
640
    }
641
    
642
    # Parse file
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
643
    my $result = $self->parse_authorized_keys_file($authorized_keys_file);
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
644
    my $before_part = $result->{before_part};
645
    my $gitprep_part = $result->{gitprep_part};
646
    my $after_part = $result->{after_part};
647
    my $start_symbol = $result->{start_symbol};
648
    my $end_symbol = $result->{end_symbol};
add key delete feature and u...
gitprep authored on 2014-05-19
649
    
650
    # Backup at first time
651
    if ($gitprep_part eq '') {
652
      # Backup original file
653
      my $to = "$authorized_keys_file.gitprep.original";
654
      unless (-f $to) {
655
        copy $authorized_keys_file, $to
656
          or croak "Can't copy $authorized_keys_file to $to";
657
      }
658
    }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
659

            
add key delete feature and u...
gitprep authored on 2014-05-19
660
    # Create public keys
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
661
    my $ssh_public_keys = $self->app->dbi->model('ssh_public_key')->select->all;
add key delete feature and u...
gitprep authored on 2014-05-19
662
    my $ssh_public_keys_str = '';
663
    for my $key (@$ssh_public_keys) {
fix permission bug
gitprep authored on 2014-05-19
664
      my $ssh_public_key_str = 'command="' . $self->app->home->rel_file('script/gitprep-shell')
665
        . " $key->{user_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $key->{key}";
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
666
      $ssh_public_keys_str .= "$ssh_public_key_str $key->{user_id}\n\n";
add key delete feature and u...
gitprep authored on 2014-05-19
667
    }
668
    
669
    # Output tmp file
fix gitprep-shell
gitprep authored on 2014-05-19
670
    my $output = "$before_part$start_symbol\n\n$ssh_public_keys_str$end_symbol$after_part";
add key delete feature and u...
gitprep authored on 2014-05-19
671
    my $output_file = "$authorized_keys_file.gitprep.tmp";
672
    open my $out_fh, '>', $output_file
673
      or croak "Can't create authorized_keys tmp file $output_file";
674
    print $out_fh $output;
675
    close $out_fh
676
      or croak "Can't close authorized_keys tmp file $output_file";
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
677

            
add key delete feature and u...
gitprep authored on 2014-05-19
678
    # Replace
fix permission bug
gitprep authored on 2014-05-19
679
    chmod 0600, $output_file
680
      or croak "Can't chmod authorized_keys tmp file: $output_file";
add key delete feature and u...
gitprep authored on 2014-05-19
681
    move $output_file, $authorized_keys_file
682
      or croak "Can't replace $authorized_keys_file by $output_file";
683
  }
684
  else {
685
    croak qq/authorized_keys file "$authorized_keys_file" is not found./;
686
  }
687
}
688

            
forbidden public key which i...
Yuki Kimoto authored on 2014-12-15
689
sub parse_authorized_keys_file {
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
690
  my ($self, $file) = @_;
add key delete feature and u...
gitprep authored on 2014-05-19
691
  
692
  my $start_symbol = "# gitprep start";
693
  my $end_symbol = "# gitprep end";
694
  
695
  # Parse
696
  open my $fh, '<', $file
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
697
    or croak "Can't open authorized_key file $file";
add key delete feature and u...
gitprep authored on 2014-05-19
698
  my $start_symbol_count = 0;
699
  my $end_symbol_count = 0;
700
  my $before_part = '';
701
  my $gitprep_part = '';
702
  my $after_part = '';
703
  my $error_prefix = "authorized_keys file $file format error:";
704
  while (my $line = <$fh>) {
705
    if ($line =~ /^$start_symbol/) {
706
      if ($start_symbol_count > 0) {
707
        croak qq/$error_prefix "$start_symbol" is found more than one/;
708
      }
709
      else {
710
        if ($end_symbol_count > 0) {
711
          croak qq/$error_prefix "$end_symbol" is found before "$start_symbol"/;
712
        }
713
        else {
714
          $start_symbol_count++;
715
        }
716
      }
717
    }
718
    elsif ($line =~ /^$end_symbol/) {
fix ssh key authentication b...
gitprep authored on 2014-05-20
719
      if ($end_symbol_count > 0) {
add key delete feature and u...
gitprep authored on 2014-05-19
720
        croak qq/$error_prefix "$end_symbol" is found more than one/;
721
      }
722
      else {
fix gitprep-shell
gitprep authored on 2014-05-19
723
        $end_symbol_count++;
add key delete feature and u...
gitprep authored on 2014-05-19
724
      }
725
    }
726
    elsif ($start_symbol_count == 0 && $end_symbol_count == 0) {
727
      $before_part .= $line;
728
    }
729
    elsif ($start_symbol_count == 1 && $end_symbol_count == 0) {
730
      $gitprep_part .= $line;
731
    }
732
    elsif ($start_symbol_count == 1 && $end_symbol_count == 1) {
733
      $after_part .= $line;
734
    }
735
  }
fix update_authorized_keys_f...
gitprep authored on 2014-05-19
736
  
737
  my $result = {
738
    start_symbol => $start_symbol,
739
    end_symbol => $end_symbol,
740
    before_part => $before_part,
741
    gitprep_part => $gitprep_part,
742
    after_part => $after_part
743
  };
744
  
745
  return $result;
add key delete feature and u...
gitprep authored on 2014-05-19
746
}
747

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
748
sub _create_project {
749
  my ($self, $user, $project, $params) = @_;
750
  $params ||= {};
751
  
752
  # Create project
cleanup
Yuki Kimoto authored on 2013-05-15
753
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
754
  $dbi->connector->txn(sub {
755
    unless (defined $params->{original_pid}) {
756
      my $number = $dbi->model('number')->select('value', where => {key => 'original_pid'})->value;
757
      $number++;
758
      $dbi->model('number')->update({value => $number}, where => {key => 'original_pid'});
759
      $params->{original_pid} = $number;
760
    }
761
    $dbi->model('project')->insert($params, id => [$user, $project]);
762
  });
763
}
764

            
765
sub _create_rep {
766
  my ($self, $user, $project, $opts) = @_;
767
  
768
  # Create repository directory
revert encoding support
Yuki Kimoto authored on 2013-11-22
769
  my $git = $self->app->git;
remove rep_path
Yuki Kimoto authored on 2016-04-16
770
  
771
  my $rep_info = $self->app->rep_info($user, $project);
772
  my $rep_git_dir = $rep_info->{git_dir};
773
  
774
  mkdir $rep_git_dir
775
    or croak "Can't create directory $rep_git_dir: $!";
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
776
  
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
777
  eval {
778
    # Git init
779
    {
remove cmd_dir
Yuki Kimoto authored on 2016-04-16
780
      my @git_init_cmd = $git->cmd($rep_info, 'init', '--bare');
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
781
      Gitprep::Util::run_command(@git_init_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
782
        or croak  "Can't execute git init --bare:@git_init_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
783
    }
784
    
785
    # Add git-daemon-export-ok
786
    {
remove rep_path
Yuki Kimoto authored on 2016-04-16
787
      my $file = "$rep_git_dir/git-daemon-export-ok";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
788
      open my $fh, '>', $file
789
        or croak "Can't create git-daemon-export-ok: $!"
790
    }
791
    
792
    # HTTP support
remove cmd_dir
Yuki Kimoto authored on 2016-04-16
793
    my @git_update_server_info_cmd = $git->cmd(
794
      $rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
795
      '--bare',
796
      'update-server-info'
797
    );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
798
    Gitprep::Util::run_command(@git_update_server_info_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
799
      or croak "Can't execute git --bare update-server-info";
remove rep_path
Yuki Kimoto authored on 2016-04-16
800
    move("$rep_git_dir/hooks/post-update.sample", "$rep_git_dir/hooks/post-update")
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
801
      or croak "Can't move post-update";
802
    
803
    # Description
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
804
    my $description = $opts->{description};
805
    $description = '' unless defined $description;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
806
    {
remove rep_path
Yuki Kimoto authored on 2016-04-16
807
      my $file = "$rep_git_dir/description";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
808
      open my $fh, '>', $file
809
        or croak "Can't open $file: $!";
810
      print $fh encode('UTF-8', $description)
811
        or croak "Can't write $file: $!";
812
      close $fh;
813
    }
814
    
815
    # Add README and commit
816
    if ($opts->{readme}) {
817
      # Create working directory
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
818
      my $home_tmp_dir = $self->app->home->rel_file('tmp');
819
      
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
820
      # Temp directory
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
821
      my $temp_dir =  File::Temp->newdir(DIR => $home_tmp_dir);
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
822
      
823
      # Working repository
824
      my $work_rep_work_tree = "$temp_dir/work";
825
      my $work_rep_git_dir = "$work_rep_work_tree/.git";
826
      my $work_rep_info = {
827
        work_tree => $work_rep_work_tree,
828
        git_dir => $work_rep_git_dir
829
      };
830
      
831
      mkdir $work_rep_work_tree
832
        or croak "Can't create directory $work_rep_work_tree: $!";
use own tmp directory to cre...
Yuki Kimoto authored on 2016-03-24
833
      
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
834
      # Git init
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
835
      my @git_init_cmd = $git->cmd($work_rep_info, 'init', '-q');
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
836
      Gitprep::Util::run_command(@git_init_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
837
        or croak "Can't execute git init: @git_init_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
838
      
839
      # Add README
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
840
      my $file = "$work_rep_work_tree/README.md";
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
841
      open my $readme_fh, '>', $file
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
842
        or croak "Can't create $file: $!";
version up and add descripti...
Yuki Kimoto authored on 2013-11-22
843
      print $readme_fh "# $project\n";
844
      print $readme_fh "\n" . encode('UTF-8', $description) . "\n";
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
845
      close $readme_fh;
846
      
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
847
      my @git_add_cmd = $git->cmd(
848
        $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
849
        'add',
default readme file is chang...
Yuki Kimoto authored on 2013-11-16
850
        'README.md'
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
851
      );
improve create working repos...
Yuki Kimoto authored on 2016-04-15
852
      
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
853
      Gitprep::Util::run_command(@git_add_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
854
        or croak "Can't execute git add: @git_add_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
855
      
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
856
      # Set user name
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
857
      my @git_config_user_name = $git->cmd(
858
        $work_rep_info,
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
859
        'config',
860
        'user.name',
861
        $user
862
      );
863
      Gitprep::Util::run_command(@git_config_user_name)
864
        or croak "Can't execute git config: @git_config_user_name";
865
      
866
      # Set user mail
867
      my $user_mail = $self->app->dbi->model('user')->select('mail', where => {id => $user})->value;
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
868
      my @git_config_user_mail = $git->cmd(
869
        $work_rep_info,
fix bug that repository with...
Yuki Kimoto authored on 2016-04-12
870
        'config',
871
        'user.email',
872
        "$user_mail"
873
      );
874
      Gitprep::Util::run_command(@git_config_user_mail)
875
        or croak "Can't execute git config: @git_config_user_mail";
876
      
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
877
      # Commit
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
878
      my @git_commit_cmd = $git->cmd(
879
        $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
880
        'commit',
881
        '-q',
882
        '-m',
883
        'first commit'
884
      );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
885
      Gitprep::Util::run_command(@git_commit_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
886
        or croak "Can't execute git commit: @git_commit_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
887
      
888
      # Push
889
      {
remove cmd_work_dir
Yuki Kimoto authored on 2016-04-16
890
        my @git_push_cmd = $git->cmd(
891
          $work_rep_info,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
892
          'push',
893
          '-q',
remove rep_path
Yuki Kimoto authored on 2016-04-16
894
          $rep_git_dir,
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
895
          'master'
896
        );
897
        # (This is bad, but --quiet option can't supress in old git)
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
898
        Gitprep::Util::run_command(@git_push_cmd)
fix git 2.0 create repositor...
Yuki Kimoto authored on 2015-11-04
899
          or croak "Can't execute git push: @git_push_cmd";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
900
      }
901
    }
902
  };
improve faq of pushing lerge...
Yuki Kimoto authored on 2014-02-17
903
  if (my $e = $@) {
remove rep_path
Yuki Kimoto authored on 2016-04-16
904
    rmtree $rep_git_dir;
improve faq of pushing lerge...
Yuki Kimoto authored on 2014-02-17
905
    croak $e;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
906
  }
907
}
908

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
909
sub _create_db_user {
910
  my ($self, $user, $data) = @_;
911
  
912
  # Create database user
913
  $self->app->dbi->model('user')->insert($data, id => $user);
914
}
915

            
916
sub _create_user_dir {
917
  my ($self, $user) = @_;
918
  
919
  # Create user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
920
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
921
  my $user_dir = "$rep_home/$user";
922
  mkpath $user_dir;
923
}
924

            
925
sub _delete_db_user {
926
  my ($self, $user) = @_;
927
  
928
  # Delete database user
added delete user test
Yuki Kimoto authored on 2013-05-18
929
  my $count = $self->app->dbi->model('user')->delete(id => $user);
930
  
931
  return $count;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
932
}
933

            
934
sub _delete_user_dir {
935
  my ($self, $user) = @_;
936
  
937
  # Delete user directory
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
938
  my $rep_home = $self->app->rep_home;
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
939
  my $user_dir = "$rep_home/$user";
940
  rmtree $user_dir;
941
}
942

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
943
sub _delete_project {
944
  my ($self, $user, $project) = @_;
945
  
cleanup
Yuki Kimoto authored on 2013-05-15
946
  # Delete project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
947
  my $dbi = $self->app->dbi;
948
  $dbi->model('project')->delete(id => [$user, $project]);
949
}
950

            
951
sub _delete_rep {
952
  my ($self, $user, $project) = @_;
953

            
cleanup
Yuki Kimoto authored on 2013-05-15
954
  # Delete repository
cleanup ->rep_home
Yuki Kimoto authored on 2016-04-14
955
  my $rep_home = $self->app->rep_home;
add missing 'o'
reneeb authored on 2013-10-14
956
  croak "Can't remove repository. repository home is empty"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
957
    if !defined $rep_home || $rep_home eq '';
958
  my $rep = "$rep_home/$user/$project.git";
959
  rmtree $rep;
960
  croak "Can't remove repository. repository is rest"
961
    if -e $rep;
962
}
963

            
fixed bug that setting page ...
Yuki Kimoto authored on 2013-05-15
964
sub exists_project {
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
965
  my ($self, $user, $project) = @_;
cleanup
Yuki Kimoto authored on 2013-05-15
966
  
967
  # Exists project
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
968
  my $dbi = $self->app->dbi;
969
  my $row = $dbi->model('project')->select(id => [$user, $project])->one;
970
  
971
  return $row ? 1 : 0;
972
}
973

            
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
974
sub exists_user {
975
  my ($self, $user) = @_;
976
  
977
  # Exists project
978
  my $row = $self->app->dbi->model('user')->select(id => $user)->one;
979
  
980
  return $row ? 1 : 0;
981
}
982

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
983
sub _exists_rep {
984
  my ($self, $user, $project) = @_;
985
  
cleanup
Yuki Kimoto authored on 2013-05-15
986
  # Exists repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
987
  my $rep_info = $self->app->rep_info($user, $project);
988
  my $rep_git_dir = $rep_info->{git_dir};
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
989
  
remove rep_path
Yuki Kimoto authored on 2016-04-16
990
  return -e $rep_git_dir;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
991
}
992

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
993
sub _fork_rep {
994
  my ($self, $user, $project, $to_user, $to_project) = @_;
995
  
cleanup
Yuki Kimoto authored on 2013-05-15
996
  # Fork repository
revert encoding support
Yuki Kimoto authored on 2013-11-22
997
  my $git = $self->app->git;
remove rep_path
Yuki Kimoto authored on 2016-04-16
998
  
999
  my $rep_info = $self->app->rep_info($user, $project);
1000
  my $rep_git_dir = $rep_info->{git_dir};
1001
  
1002
  my $to_rep_info = $self->app->rep_info($to_user, $to_project);
1003
  my $to_rep_git_dir = $to_rep_info->{git_dir};
1004

            
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
1005
  my @cmd = (
1006
    $git->bin,
1007
    'clone',
1008
    '-q',
1009
    '--bare',
remove rep_path
Yuki Kimoto authored on 2016-04-16
1010
    $rep_git_dir,
1011
    $to_rep_git_dir
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
1012
  );
fix bug that in CGI reposito...
Yuki Kimoto authored on 2015-11-05
1013
  Gitprep::Util::run_command(@cmd)
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
1014
    or croak "Can't fork repository(_fork_rep): @cmd";
1015
  
1016
  # Copy description
remove rep_path
Yuki Kimoto authored on 2016-04-16
1017
  copy "$rep_git_dir/description", "$to_rep_git_dir/description"
fix description file not cop...
Yuki Kimoto authored on 2013-05-25
1018
    or croak "Can't copy description file(_fork_rep)";
show deleted repository in u...
Yuki Kimoto authored on 2013-05-15
1019
}
1020

            
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1021
sub _rename_project {
1022
  my ($self, $user, $project, $renamed_project) = @_;
1023
  
cleanup
Yuki Kimoto authored on 2013-05-15
1024
  # Check arguments
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
1025
  croak "Invalid parameters(_rename_project)"
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1026
    unless defined $user && defined $project && defined $renamed_project;
1027
  
1028
  # Rename project
cleanup
Yuki Kimoto authored on 2013-05-15
1029
  my $dbi = $self->app->dbi;
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1030
  $dbi->model('project')->update(
1031
    {name => $renamed_project},
1032
    id => [$user, $project]
1033
  );
1034
}
1035

            
1036
sub _rename_rep {
1037
  my ($self, $user, $project, $renamed_project) = @_;
1038
  
cleanup
Yuki Kimoto authored on 2013-05-15
1039
  # Check arguments
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1040
  croak "Invalid user name or project"
1041
    unless defined $user && defined $project && defined $renamed_project;
cleanup
Yuki Kimoto authored on 2013-05-15
1042

            
1043
  # Rename repository
remove rep_path
Yuki Kimoto authored on 2016-04-16
1044
  my $rep_info = $self->app->rep_info($user, $project);
1045
  my $rep_git_dir = $rep_info->{git_dir};
1046
  
1047
  my $renamed_rep_info = $self->app->rep_info($user, $renamed_project);
1048
  my $renamed_rep_git_dir = $renamed_rep_info->{git_dir};
1049

            
1050
  move($rep_git_dir, $renamed_rep_git_dir)
1051
    or croak "Can't move $rep_git_dir to $renamed_rep_git_dir: $!";
fixed tags page paging bug a...
Yuki Kimoto authored on 2013-05-01
1052
}
1053

            
1054
1;