Commit acf84bb1 authored by Alessio Caiazza's avatar Alessio Caiazza

Refactor diverged check

parent 8e4e0631
...@@ -60,24 +60,14 @@ module EE ...@@ -60,24 +60,14 @@ module EE
upstream_branch = upstream_branch_name(branch_name) upstream_branch = upstream_branch_name(branch_name)
return false unless upstream_branch return false unless upstream_branch
branch_commit = commit("refs/heads/#{branch_name}") diverged?(branch_name, MIRROR_REMOTE, upstream_branch_name: upstream_branch) do |branch_commit, upstream_commit|
upstream_commit = commit("refs/remotes/#{MIRROR_REMOTE}/#{upstream_branch}")
if branch_commit && upstream_commit
!raw_repository.ancestor?(branch_commit.id, upstream_commit.id) !raw_repository.ancestor?(branch_commit.id, upstream_commit.id)
else
false
end end
end end
def upstream_has_diverged?(branch_name, remote_ref) def upstream_has_diverged?(branch_name, remote_ref)
branch_commit = commit("refs/heads/#{branch_name}") diverged?(branch_name, remote_ref) do |branch_commit, upstream_commit|
upstream_commit = commit("refs/remotes/#{remote_ref}/#{branch_name}")
if branch_commit && upstream_commit
!raw_repository.ancestor?(upstream_commit.id, branch_commit.id) !raw_repository.ancestor?(upstream_commit.id, branch_commit.id)
else
false
end end
end end
...@@ -85,13 +75,8 @@ module EE ...@@ -85,13 +75,8 @@ module EE
upstream_branch = upstream_branch_name(branch_name) upstream_branch = upstream_branch_name(branch_name)
return false unless upstream_branch return false unless upstream_branch
branch_commit = commit("refs/heads/#{branch_name}") diverged?(branch_name, MIRROR_REMOTE, upstream_branch_name: upstream_branch) do |branch_commit, upstream_commit|
upstream_commit = commit("refs/remotes/#{MIRROR_REMOTE}/#{upstream_branch}")
if branch_commit && upstream_commit
ancestor?(branch_commit.id, upstream_commit.id) ancestor?(branch_commit.id, upstream_commit.id)
else
false
end end
end end
...@@ -123,5 +108,18 @@ module EE ...@@ -123,5 +108,18 @@ module EE
def insights_config_for(sha) def insights_config_for(sha)
blob_data_at(sha, ::Gitlab::Insights::CONFIG_FILE_PATH) blob_data_at(sha, ::Gitlab::Insights::CONFIG_FILE_PATH)
end end
private
def diverged?(branch_name, remote_ref, upstream_branch_name: branch_name)
branch_commit = commit("refs/heads/#{branch_name}")
upstream_commit = commit("refs/remotes/#{remote_ref}/#{upstream_branch_name}")
if branch_commit && upstream_commit
yield branch_commit, upstream_commit
else
false
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment