Commit b3834bc9b03566252ca83f70f4af882561ac261f
1 parent
2b1afa0e
Exists in
master
and in
4 other branches
Remove MergeRequest#to_raw and replace it with #to_diff and #to_patch
Showing
1 changed file
with
14 additions
and
12 deletions
Show diff stats
app/models/merge_request.rb
| @@ -202,20 +202,22 @@ class MergeRequest < ActiveRecord::Base | @@ -202,20 +202,22 @@ class MergeRequest < ActiveRecord::Base | ||
| 202 | false | 202 | false |
| 203 | end | 203 | end |
| 204 | 204 | ||
| 205 | - def to_raw | ||
| 206 | - FileUtils.mkdir_p(Rails.root.join("tmp", "patches")) | ||
| 207 | - patch_path = Rails.root.join("tmp", "patches", "merge_request_#{self.id}.patch") | ||
| 208 | - | ||
| 209 | - from = commits.last.id | ||
| 210 | - to = source_branch | ||
| 211 | - | ||
| 212 | - project.repo.git.run('', "format-patch" , " > #{patch_path.to_s}", {}, ["#{from}..#{to}", "--stdout"]) | ||
| 213 | - | ||
| 214 | - patch_path | ||
| 215 | - end | ||
| 216 | - | ||
| 217 | def mr_and_commit_notes | 205 | def mr_and_commit_notes |
| 218 | commit_ids = commits.map(&:id) | 206 | commit_ids = commits.map(&:id) |
| 219 | Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) | 207 | Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) |
| 220 | end | 208 | end |
| 209 | + | ||
| 210 | + # Returns the raw diff for this merge request | ||
| 211 | + # | ||
| 212 | + # see "git diff" | ||
| 213 | + def to_diff | ||
| 214 | + project.repo.git.native(:diff, {timeout: 30, raise: true}, "#{target_branch}...#{source_branch}") | ||
| 215 | + end | ||
| 216 | + | ||
| 217 | + # Returns the commit as a series of email patches. | ||
| 218 | + # | ||
| 219 | + # see "git format-patch" | ||
| 220 | + def to_patch | ||
| 221 | + project.repo.git.format_patch({timeout: 30, raise: true, stdout: true}, "#{target_branch}..#{source_branch}") | ||
| 222 | + end | ||
| 221 | end | 223 | end |