Showing 2 changed files with 47 additions and 1 deletions
+34
lib/Gitprep/Manager.pm
... ...
@@ -15,6 +15,40 @@ use Gitprep::Util;
15 15
 has 'app';
16 16
 has 'authorized_keys_file';
17 17
 
18
+sub check_merge_automatical {
19
+  my ($self, $rep_info, $branch1, $branch2) = @_;
20
+  
21
+  # Create patch
22
+  my @git_format_patch_cmd = $self->app->git->cmd(
23
+    $rep_info,
24
+    'format-patch',
25
+    "$branch1..$branch2",
26
+    "--stdout"
27
+  );
28
+  open my $git_format_patch_fh, '-|', @git_format_patch_cmd
29
+    or Carp::croak "Can't execute git format-patch: @git_format_patch_cmd";
30
+  my $patch_str = do { local $/; <$git_format_patch_fh> };
31
+  
32
+  # Write patch to file
33
+  my $tmp_dir = File::Temp->newdir(DIR => $self->app->home->rel_file('/tmp'));
34
+  my $patch_file = "$tmp_dir/test.patch";
35
+  open my $patch_fh, '>', $patch_file
36
+    or Carp::croak "Can't open patch file $patch_file: $!";
37
+  print $patch_fh $patch_str;
38
+  close $patch_fh;
39
+  
40
+  # Check if this patch can be applied
41
+  my @git_apply_cmd = $self->app->git->cmd(
42
+    $rep_info,
43
+    'apply',
44
+    $patch_file,
45
+    '--check'
46
+  );
47
+  my $automatical = Gitprep::Util::run_command(@git_apply_cmd);
48
+  
49
+  return $automatical;
50
+}
51
+
18 52
 sub create_work_rep {
19 53
   my ($self, $user, $project) = @_;
20 54
   
+13 -1
templates/compare.html.ep
... ...
@@ -58,7 +58,7 @@
58 58
   }
59 59
   
60 60
   # Can merge
61
-  my $can_merge;
61
+  my $merge_automatical;
62 62
   if ($can_open_pull_request) {
63 63
     
64 64
     # Create working repository if it don't exist
... ...
@@ -92,6 +92,12 @@
92 92
     Gitprep::Util::run_command(@git_reset_hard_cmd)
93 93
       or Carp::croak "Can't execute git reset --hard: @git_reset_hard_cmd";
94 94
     
95
+    # Check merge automatically
96
+    $merge_automatical = $self->app->manager->check_merge_automatical(
97
+      app->work_rep_info($user, $project),
98
+      $gitprep_tmp_branch_name,
99
+      "origin/$rev"
100
+    );
95 101
   }
96 102
   
97 103
   layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project";
... ...
@@ -159,6 +165,12 @@
159 165
         <button id="compare-branch-btn" class="btn btn-small">
160 166
           <span>compare:</span> <b><%= $rev %></b><i class="icon-arrow-down"></i>
161 167
         </button>
168
+        
169
+        % if ($merge_automatical) {
170
+          <span style="margin-left:10px">
171
+            <span style="color:green;font-weight:bold"><%= "\x{2714}" %>Able to merge.</span> These branches can be automatically merged.
172
+          </span>
173
+        % }
162 174
       </div>
163 175
     </div>
164 176