summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-01-31 11:02:09 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-01-31 11:02:09 +0000
commitdacd9dbef4b245f7da5640e3638eae05e9678992 (patch)
treeed8b933ce74c61972ae1cbcecf3aee538b3468ed
parentf8250f8fd0cfec10a639b8a010331197a9e1c40e (diff)
parent11191f938c3b865dbb3e203ecdb018fd91bd0c91 (diff)
downloadgitlab-ce-dacd9dbef4b245f7da5640e3638eae05e9678992.tar.gz
Merge branch 'fix/move-can-be-merged-to-lib-git' into 'master'
Move Repository#can_be_merged? to Gitlab::Git::Repository Closes #42544 See merge request gitlab-org/gitlab-ce!16771
-rw-r--r--app/models/repository.rb2
-rw-r--r--lib/gitlab/git/repository.rb18
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 6c776301ac2..406e3a7f73b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -852,7 +852,7 @@ class Repository
@root_ref_sha ||= commit(root_ref).sha
end
- delegate :merged_branch_names, to: :raw_repository
+ delegate :merged_branch_names, :can_be_merged?, to: :raw_repository
def merge_base(first_commit_id, second_commit_id)
first_commit_id = commit(first_commit_id).try(:id) || first_commit_id
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 7127f7858ee..8137c582c0f 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1386,6 +1386,16 @@ module Gitlab
run_git(args).first.scrub.split(/^--$/)
end
+ def can_be_merged?(source_sha, target_branch)
+ gitaly_migrate(:can_be_merged) do |is_enabled|
+ if is_enabled
+ gitaly_can_be_merged?(source_sha, find_branch(target_branch, true).target)
+ else
+ rugged_can_be_merged?(source_sha, target_branch)
+ end
+ end
+ end
+
def search_files_by_name(query, ref)
safe_query = Regexp.escape(query.sub(/^\/*/, ""))
@@ -2280,6 +2290,14 @@ module Gitlab
run_git(['fetch', remote_name], env: env).last.zero?
end
+ def gitaly_can_be_merged?(their_commit, our_commit)
+ !gitaly_conflicts_client(our_commit, their_commit).conflicts?
+ end
+
+ def rugged_can_be_merged?(their_commit, our_commit)
+ !rugged.merge_commits(our_commit, their_commit).conflicts?
+ end
+
def gitlab_projects_error
raise CommandError, @gitlab_projects.output
end