summaryrefslogtreecommitdiff
path: root/app/models/repository.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb39
1 files changed, 36 insertions, 3 deletions
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)