Skip to content

Commit

Permalink
Merge pull request #1263 from dosire/merge_base_for_merge_request
Browse files Browse the repository at this point in the history
Show only the commits that are newer in the merge request.
  • Loading branch information
dzaporozhets committed Aug 23, 2012
2 parents a94b2d1 + 9ec4c2d commit 7ab587a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/merge_request.rb
Expand Up @@ -88,8 +88,11 @@ def valid_diffs?
end

def unmerged_diffs
commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue []
# Only show what is new in the source branch compared to the target branch, not the other way around.
# The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = project.repo.git.native(:merge_base, {}, [target_branch, source_branch]).strip
diffs = project.repo.diff(common_commit, source_branch)
end

def last_commit
Expand Down

0 comments on commit 7ab587a

Please sign in to comment.