... | ... |
@@ -1,2 +1,4 @@ |
1 |
+1.1 |
|
2 |
+ - add import_rep script to import repositories. |
|
1 | 3 |
1.0 |
2 | 4 |
- first major release |
... | ... |
@@ -0,0 +1,102 @@ |
1 |
+#!/usr/bin/env perl |
|
2 |
+ |
|
3 |
+use strict; |
|
4 |
+use warnings; |
|
5 |
+use utf8; |
|
6 |
+use FindBin; |
|
7 |
+use lib "$FindBin::Bin/../mojo/lib"; |
|
8 |
+use lib "$FindBin::Bin/../lib"; |
|
9 |
+use lib "$FindBin::Bin/../extlib/lib/perl5"; |
|
10 |
+use Getopt::Long; |
|
11 |
+use File::Basename 'basename'; |
|
12 |
+use Gitprep; |
|
13 |
+use Encode 'decode'; |
|
14 |
+ |
|
15 |
+no warnings; |
|
16 |
+my $app = Gitprep->new; |
|
17 |
+my $dbi = $app->dbi; |
|
18 |
+my $manager = $app->manager; |
|
19 |
+my $git = $app->git; |
|
20 |
+ |
|
21 |
+my $user; |
|
22 |
+my $only_push; |
|
23 |
+ |
|
24 |
+GetOptions( |
|
25 |
+ 'user=s' => \$user, |
|
26 |
+); |
|
27 |
+ |
|
28 |
+my $rep_dir = shift; |
|
29 |
+ |
|
30 |
+# Check user |
|
31 |
+my $user_row = $dbi->model('user')->select(id => $user)->one; |
|
32 |
+die "User $user is not exists\n" unless $user_row; |
|
33 |
+ |
|
34 |
+for my $rep (glob "$rep_dir/*") { |
|
35 |
+ |
|
36 |
+ if (-d $rep && $rep =~ /\.git$/) { |
|
37 |
+ my $project = basename $rep; |
|
38 |
+ $project =~ s/\.git$//; |
|
39 |
+ |
|
40 |
+ my $project_row = $dbi->model('project')->select(id => [$user, $project])->one; |
|
41 |
+ |
|
42 |
+ # Create project |
|
43 |
+ if ($project_row) { |
|
44 |
+ warn "Repository $project Already exists : $@\n"; |
|
45 |
+ } |
|
46 |
+ else { |
|
47 |
+ eval { |
|
48 |
+ $manager->create_project($user, $project); |
|
49 |
+ }; |
|
50 |
+ if ($@) { |
|
51 |
+ warn "Can't creat repository $project: $@\n"; |
|
52 |
+ } |
|
53 |
+ else { |
|
54 |
+ warn "Create repository $project\n"; |
|
55 |
+ } |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ # Copy description |
|
59 |
+ my $description = do { |
|
60 |
+ my $success = open my $fh, '<', "$rep/description"; |
|
61 |
+ |
|
62 |
+ if ($success) { |
|
63 |
+ local $/; |
|
64 |
+ <$fh> |
|
65 |
+ } |
|
66 |
+ else { |
|
67 |
+ ''; |
|
68 |
+ } |
|
69 |
+ }; |
|
70 |
+ $description = decode('UTF-8', $description); |
|
71 |
+ eval {$git->description($user, $project, $description) }; |
|
72 |
+ if ($@) { |
|
73 |
+ warn "Can't update description $project\n"; |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ # Push repository |
|
77 |
+ chdir $rep |
|
78 |
+ or warn "Can't change directory $rep: $!\n"; |
|
79 |
+ my $remote_rep = "$FindBin::Bin/../data/rep/$user/$project.git"; |
|
80 |
+ my @cmd = ('git', 'push', '-u', $remote_rep, 'master'); |
|
81 |
+ system(@cmd) == 0 |
|
82 |
+ or warn "Can't push repository: @cmd"; |
|
83 |
+ } |
|
84 |
+} |
|
85 |
+ |
|
86 |
+=head1 NAME |
|
87 |
+ |
|
88 |
+import_rep - create repositories |
|
89 |
+ |
|
90 |
+=head1 USAGE |
|
91 |
+ |
|
92 |
+ ./import_rep -u kimoto rep_dir |
|
93 |
+ |
|
94 |
+rep_dir must contains git respoitories |
|
95 |
+ |
|
96 |
+ rep_dir/project1.git |
|
97 |
+ /project2.git |
|
98 |
+ /project3.git |
|
99 |
+ /project3.git |
|
100 |
+ |
|
101 |
+If C<description> file exists in git repository, it is copied. |
|
102 |
+ |