Showing 4 changed files with 48 additions and 19 deletions
+1 -1
lib/Gitprep.pm
... ...
@@ -52,7 +52,7 @@ sub rep_path {
52 52
 sub rep_work_home {
53 53
   my $self = shift;
54 54
   
55
-  my $work_home = $self->work_home . "/work";
55
+  my $work_home = $self->data_dir . "/work";
56 56
   
57 57
   return $work_home;
58 58
 }
+1 -13
lib/Gitprep/Git.pm
... ...
@@ -121,18 +121,6 @@ sub branches_count {
121 121
   return $branches_count;
122 122
 }
123 123
 
124
-sub cmd_clone {
125
-  my ($self, $user, $project) = @_;
126
-
127
-  # Repository
128
-  my $rep = $self->app->rep_path($user, $project);
129
-  
130
-  # Working directory
131
-  my $rep_work = $self->app->rep_work_path($user, $project);
132
-  
133
-  return ($self->bin, 'clone', $rep, $rep_work)
134
-}
135
-
136 124
 sub cmd_rep {
137 125
   my ($self, $user, $project, @cmd) = @_;
138 126
   
... ...
@@ -160,7 +148,7 @@ sub cmd_rep_work {
160 148
 sub cmd_work_dir {
161 149
   my ($self, $dir, @cmd) = @_;
162 150
   
163
-  return ($self->bin, "--git-dir=$dir", "--work-tree=$dir",  @cmd);
151
+  return ($self->bin, "--git-dir=$dir/.git", "--work-tree=$dir",  @cmd);
164 152
 }
165 153
 
166 154
 sub authors {
+44 -1
lib/Gitprep/Manager.pm
... ...
@@ -15,6 +15,48 @@ use Gitprep::Util;
15 15
 has 'app';
16 16
 has 'authorized_keys_file';
17 17
 
18
+sub create_rep_work {
19
+  my ($self, $user, $project) = @_;
20
+  
21
+  # Create working repository if it don't exist
22
+  my $rep_work = $self->app->rep_work_path($user, $project);
23
+  unless (-e $rep_work) {
24
+    # Repository
25
+    my $rep = $self->app->rep_path($user, $project);
26
+    
27
+    # Working directory
28
+    my $rep_work = $self->app->rep_work_path($user, $project);
29
+    
30
+    # git clone
31
+    my @git_clone_cmd = ($self->app->git->bin, 'clone', $rep, $rep_work);
32
+    Gitprep::Util::run_command(@git_clone_cmd)
33
+      or croak "Can't git clone: @git_clone_cmd";
34
+    
35
+    warn $rep_work;
36
+
37
+    # Set user name
38
+    my @git_config_user_name = $self->app->git->cmd_work_dir(
39
+      $rep_work,
40
+      'config',
41
+      'user.name',
42
+      $user
43
+    );
44
+    Gitprep::Util::run_command(@git_config_user_name)
45
+      or croak "Can't execute git config: @git_config_user_name";
46
+    
47
+    # Set user mail
48
+    my $user_mail = $self->app->dbi->model('user')->select('mail', where => {id => $user})->value;
49
+    my @git_config_user_mail = $self->app->git->cmd_work_dir(
50
+      $rep_work,
51
+      'config',
52
+      'user.email',
53
+      "$user_mail"
54
+    );
55
+    Gitprep::Util::run_command(@git_config_user_mail)
56
+      or croak "Can't execute git config: @git_config_user_mail";
57
+  }
58
+}
59
+
18 60
 sub admin_user {
19 61
   my $self = shift;
20 62
   
... ...
@@ -689,7 +731,7 @@ sub _create_rep {
689 731
         or croak "Can't create directory $temp_work: $!";
690 732
       
691 733
       # Git init
692
-      my @git_init_cmd = $git->cmd_dir($temp_work, 'init', '-q');
734
+      my @git_init_cmd = $git->cmd_work_dir($temp_work, 'init', '-q');
693 735
       Gitprep::Util::run_command(@git_init_cmd)
694 736
         or croak "Can't execute git init: @git_init_cmd";
695 737
       
... ...
@@ -706,6 +748,7 @@ sub _create_rep {
706 748
         'add',
707 749
         'README.md'
708 750
       );
751
+      
709 752
       Gitprep::Util::run_command(@git_add_cmd)
710 753
         or croak "Can't execute git add: @git_add_cmd";
711 754
       
+2 -4
templates/compare.html.ep
... ...
@@ -61,10 +61,8 @@
61 61
   my $can_merge;
62 62
   if ($can_open_pull_request) {
63 63
     
64
-    # Clone repository to working directory if it don't exist
65
-    # my @git_clone_cmd = $self->app->git->cmd_clone($user, $project);
66
-    # Gitprep::Util::run_command(@git_clone_cmd)
67
-    #  or die "Can't git clone: @git_clone_cmd";
64
+    # Create working repository if it don't exist
65
+    $self->app->manager->create_rep_work($user, $project);
68 66
   }
69 67
   
70 68
   layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project";