summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/merge_request.rb12
-rw-r--r--app/models/repository.rb39
2 files changed, 48 insertions, 3 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 157901378d3..d3a611414cb 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -321,6 +321,18 @@ class MergeRequest < ActiveRecord::Base
end
end
+ def conflicts?
+ project.repository.conflicts?(diff_head_sha, target_branch)
+ end
+
+ def conflicts
+ project.repository.conflicts(diff_head_sha, target_branch)
+ end
+
+ def conflict_diff(conflict)
+ project.repository.conflict_diff(diff_head_sha, target_branch, conflict[:ancestor][:path])
+ end
+
def merge_event
@merge_event ||= target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 5b670cb4b8f..edcfe401340 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -637,11 +637,11 @@ class Repository
def contributors
commits = self.commits(nil, limit: 2000, offset: 0, skip_merges: true)
- commits.group_by(&:author_email).map do |email, commits|
+ commits.group_by(&:author_email).map do |author_email, author_commits|
contributor = Gitlab::Contributor.new
- contributor.email = email
+ contributor.email = author_email
- commits.each do |commit|
+ author_commits.each do |commit|
if contributor.name.blank?
contributor.name = commit.author_name
end
@@ -769,6 +769,39 @@ class Repository
end
end
+ def conflicts?(source_sha, target_branch)
+ our_commit = rugged.branches[target_branch].target
+ their_commit = rugged.lookup(source_sha)
+
+ if our_commit && their_commit
+ rugged.merge_commits(our_commit, their_commit).conflicts?
+ else
+ false
+ end
+ end
+
+ def conflicts(source_sha, target_branch)
+ our_commit = rugged.branches[target_branch].target
+ their_commit = rugged.lookup(source_sha)
+
+ if our_commit && their_commit
+ rugged.merge_commits(our_commit, their_commit).conflicts
+ else
+ []
+ end
+ end
+
+ def conflict_diff(source_sha, target_branch, path)
+ our_commit = rugged.branches[target_branch].target
+ their_commit = rugged.lookup(source_sha)
+
+ if our_commit && their_commit && path
+ rugged.diff(our_commit, their_commit, { paths: [path], context_lines: 3 })
+ else
+ []
+ end
+ end
+
def merge(user, source_sha, target_branch, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source_sha)