Commit 9ec4c2d214b045f3fb207edd67055c4ccaebd381

Authored by Sytse Sijbrandij
1 parent 64f3682f

Show only the commits that are newer in the merge request.

Showing 1 changed file with 5 additions and 2 deletions   Show diff stats
app/models/merge_request.rb
@@ -88,8 +88,11 @@ class MergeRequest < ActiveRecord::Base @@ -88,8 +88,11 @@ class MergeRequest < ActiveRecord::Base
88 end 88 end
89 89
90 def unmerged_diffs 90 def unmerged_diffs
91 - commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}  
92 - diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue [] 91 + # Only show what is new in the source branch compared to the target branch, not the other way around.
  92 + # The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
  93 + # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
  94 + common_commit = project.repo.git.native(:merge_base, {}, [target_branch, source_branch]).strip
  95 + diffs = project.repo.diff(common_commit, source_branch)
93 end 96 end
94 97
95 def last_commit 98 def last_commit