lib/gitlab_git/diff.rb in gitlab_git-1.4.1 vs lib/gitlab_git/diff.rb in gitlab_git-2.0.0.beta
- old
+ new
@@ -12,9 +12,24 @@
attr_accessor :old_path, :new_path, :a_mode, :b_mode, :diff
# Stats properties
attr_accessor :new_file, :renamed_file, :deleted_file
+ class << self
+ def between(repo, from, to)
+ # 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 = repo.merge_base_commit(from, to)
+
+ repo.diff(common_commit, from).map do |diff|
+ Gitlab::Git::Diff.new(diff)
+ end
+ rescue Grit::Git::GitTimeout
+ [Gitlab::Git::Diff::BROKEN_DIFF]
+ end
+ end
+
def initialize(raw_diff)
raise "Nil as raw diff passed" unless raw_diff
if raw_diff.is_a?(Hash)
init_from_hash(raw_diff)