Commit 246faa3d7a60ea2296a24d0c5de1a71a7a48854b
1 parent
8b401039
Exists in
master
and in
4 other branches
Add Commit#to_diff for raw diff
Showing
1 changed file
with
15 additions
and
0 deletions
Show diff stats
app/models/commit.rb
| ... | ... | @@ -150,4 +150,19 @@ class Commit |
| 150 | 150 | def parents_count |
| 151 | 151 | parents && parents.count || 0 |
| 152 | 152 | end |
| 153 | + | |
| 154 | + # Shows the diff between the commit's parent and the commit. | |
| 155 | + # | |
| 156 | + # Cuts out the header and stats from #to_patch and returns only the diff. | |
| 157 | + def to_diff | |
| 158 | + # see Grit::Commit#show | |
| 159 | + patch = to_patch | |
| 160 | + | |
| 161 | + # discard lines before the diff | |
| 162 | + lines = patch.split("\n") | |
| 163 | + while !lines.first.start_with?("diff --git") do | |
| 164 | + lines.shift | |
| 165 | + end | |
| 166 | + lines.join("\n") | |
| 167 | + end | |
| 153 | 168 | end | ... | ... |