Showing 2 changed files with 18 additions and 6 deletions
+15 -4
lib/Gitprep/Manager.pm
... ...
@@ -15,6 +15,21 @@ use Gitprep::Util;
15 15
 has 'app';
16 16
 has 'authorized_keys_file';
17 17
 
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
+
18 33
 sub check_merge_automatical {
19 34
   my ($self, $rep_info, $branch1, $branch2) = @_;
20 35
   
... ...
@@ -631,10 +646,6 @@ sub update_authorized_keys_file {
631 646
       or croak "Can't chmod authorized_keys tmp file: $output_file";
632 647
     move $output_file, $authorized_keys_file
633 648
       or croak "Can't replace $authorized_keys_file by $output_file";
634
-    
635
-    # Unlock file
636
-    flock $lock_fh, LOCK_EX
637
-      or croak "Can't unlock $lock_file"
638 649
   }
639 650
   else {
640 651
     croak qq/authorized_keys file "$authorized_keys_file" is not found./;
+3 -2
templates/compare.html.ep
... ...
@@ -70,10 +70,11 @@
70 70
     Gitprep::Util::run_command(@git_fetch_cmd)
71 71
       or Carp::croak "Can't execute git fetch: @git_fetch_cmd";
72 72
     
73
-    # git checkout -b origin/$from_rev
74
-    my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__';
73
+    # Lock repository
74
+    my $lock = $self->app->manager->lock_rep($work_rep_info);
75 75
     
76 76
     # Checkout tmp branch and git reset --hard from my remote branch
77
+    my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__';
77 78
     my @git_checkout_tmp_branch = $self->app->git->cmd(
78 79
       $work_rep_info,
79 80
       'checkout',