... | ... |
@@ -417,6 +417,7 @@ sub startup { |
417 | 417 |
$r->get('/pulls' => sub { shift->render_maybe('/pulls') })->to(tab => 'pulls'); |
418 | 418 |
|
419 | 419 |
# Pull request |
420 |
+ $r->get('/pull/(:row_id).patch' => sub { shift->render_maybe('/pull') })->to(tab => 'pulls', patch => 1); |
|
420 | 421 |
$r->any('/pull/:row_id' => sub { shift->render_maybe('/pull') })->to(tab => 'pulls'); |
421 | 422 |
|
422 | 423 |
# Commit |
... | ... |
@@ -129,6 +129,27 @@ sub merge { |
129 | 129 |
return $success; |
130 | 130 |
} |
131 | 131 |
|
132 |
+sub get_patch { |
|
133 |
+ my ($self, $work_rep_info, $target_rep_info, $target_branch) = @_; |
|
134 |
+ |
|
135 |
+ my $object_id = $self->app->git->ref_to_object_id($target_rep_info, $target_branch); |
|
136 |
+ |
|
137 |
+ # Merge |
|
138 |
+ my @git_format_patch_cmd = $self->app->git->cmd( |
|
139 |
+ $work_rep_info, |
|
140 |
+ 'format-patch', |
|
141 |
+ '--stdout', |
|
142 |
+ "HEAD..$object_id" |
|
143 |
+ ); |
|
144 |
+ |
|
145 |
+ open my $fh, '-|', @git_format_patch_cmd |
|
146 |
+ or croak "Execute git format-patch cmd:@git_format_patch_cmd"; |
|
147 |
+ |
|
148 |
+ my $patch = do { local $/; <$fh> }; |
|
149 |
+ |
|
150 |
+ return $patch; |
|
151 |
+} |
|
152 |
+ |
|
132 | 153 |
sub push { |
133 | 154 |
my ($self, $work_rep_info, $base_branch) = @_; |
134 | 155 |
|
... | ... |
@@ -57,7 +57,33 @@ |
57 | 57 |
|
58 | 58 |
# Working repository information |
59 | 59 |
my $work_rep_info = app->work_rep_info($base_user_id, $base_project_id); |
60 |
- |
|
60 |
+ |
|
61 |
+ # Display patch |
|
62 |
+ if (stash('patch')) { |
|
63 |
+ # Lock working repository |
|
64 |
+ my $lock_fh = $self->app->manager->lock_rep($work_rep_info); |
|
65 |
+ |
|
66 |
+ # Prepare merge |
|
67 |
+ $self->app->manager->prepare_merge( |
|
68 |
+ $work_rep_info, |
|
69 |
+ $base_rep_info, |
|
70 |
+ $base_branch, |
|
71 |
+ $target_rep_info, |
|
72 |
+ $target_branch |
|
73 |
+ ); |
|
74 |
+ |
|
75 |
+ # Create patch |
|
76 |
+ my $patch = $self->app->manager->get_patch( |
|
77 |
+ $work_rep_info, |
|
78 |
+ $target_rep_info, |
|
79 |
+ $target_branch |
|
80 |
+ ); |
|
81 |
+ |
|
82 |
+ $self->res->headers->content_type('text/plain; charset=utf-8'); |
|
83 |
+ $self->render(text => $patch); |
|
84 |
+ return; |
|
85 |
+ } |
|
86 |
+ |
|
61 | 87 |
# Git |
62 | 88 |
my $git = $self->app->git; |
63 | 89 |
|