From 246faa3d7a60ea2296a24d0c5de1a71a7a48854b Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 22 Nov 2012 20:49:01 +0100 Subject: [PATCH] Add Commit#to_diff for raw diff --- app/models/commit.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/models/commit.rb b/app/models/commit.rb index 5efb20ce..200c915a 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -150,4 +150,19 @@ class Commit def parents_count parents && parents.count || 0 end + + # Shows the diff between the commit's parent and the commit. + # + # Cuts out the header and stats from #to_patch and returns only the diff. + def to_diff + # see Grit::Commit#show + patch = to_patch + + # discard lines before the diff + lines = patch.split("\n") + while !lines.first.start_with?("diff --git") do + lines.shift + end + lines.join("\n") + end end