Commit 720c9d60 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '5869-rebase-before-checking-ce-branch' into 'master'

Resolve "ee-specific-lines-check should not check against CE master"

Closes #5869

See merge request gitlab-org/gitlab-ee!5564
parents 5bff360e c41b90bf
...@@ -69,6 +69,8 @@ eslint-report.html ...@@ -69,6 +69,8 @@ eslint-report.html
/shared/* /shared/*
/.gitlab_workhorse_secret /.gitlab_workhorse_secret
/webpack-report/ /webpack-report/
/knapsack/
/rspec_flaky/
/locale/**/LC_MESSAGES /locale/**/LC_MESSAGES
/locale/**/*.time_stamp /locale/**/*.time_stamp
/.rspec /.rspec
......
# frozen_string_literal: true
module EESpecificCheck module EESpecificCheck
WHITELIST = [ WHITELIST = [
'CHANGELOG-EE.md', 'CHANGELOG-EE.md',
...@@ -23,15 +25,15 @@ module EESpecificCheck ...@@ -23,15 +25,15 @@ module EESpecificCheck
def find_compare_base def find_compare_base
setup_canonical_remotes setup_canonical_remotes
fetch_head_ce = fetch_remote_ce_branch ce_fetch_head = fetch_remote_ce_branch
ce_merge_base = run_git_command("merge-base #{fetch_head_ce} HEAD").strip ce_merge_base = run_git_command("merge-base canonical-ce/master canonical-ee/master")
ee_merge_base = run_git_command("merge-base canonical-ee/master HEAD").strip ee_merge_base = run_git_command("merge-base canonical-ee/master HEAD")
ce_updated_base = ce_updated_base =
if fetch_head_ce.start_with?('canonical-ce') if ce_fetch_head.start_with?('canonical-ce')
ce_merge_base # Compare with merge-base if no specific CE branch ce_merge_base # Compare with merge-base if no specific CE branch
else else
fetch_head_ce # Compare with the new HEAD if we do have one checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(ce_merge_base, ce_fetch_head)
end end
CompareBase.new(ce_merge_base, ee_merge_base, ce_updated_base) CompareBase.new(ce_merge_base, ee_merge_base, ce_updated_base)
...@@ -40,9 +42,9 @@ module EESpecificCheck ...@@ -40,9 +42,9 @@ module EESpecificCheck
def setup_canonical_remotes def setup_canonical_remotes
run_git_command( run_git_command(
"remote add canonical-ee https://gitlab.com/gitlab-org/gitlab-ee.git", "remote add canonical-ee https://gitlab.com/gitlab-org/gitlab-ee.git",
"remote add canonical-ce https://gitlab.com/gitlab-org/gitlab-ce.git") "remote add canonical-ce https://gitlab.com/gitlab-org/gitlab-ce.git",
"fetch canonical-ee master --quiet",
run_git_command("fetch canonical-ee master --quiet") "fetch canonical-ce master --quiet")
end end
def fetch_remote_ce_branch def fetch_remote_ce_branch
...@@ -53,6 +55,77 @@ module EESpecificCheck ...@@ -53,6 +55,77 @@ module EESpecificCheck
"#{remote_to_fetch}/#{branch_to_fetch}" "#{remote_to_fetch}/#{branch_to_fetch}"
end end
def checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(ce_merge_base, ce_fetch_head)
# So that we could switch back
head = head_commit_sha
# Use detached HEAD so that we don't update HEAD
run_git_command("checkout #{ce_fetch_head}")
# We rebase onto the commit which is the latest commit presented in both
# CE and EE, i.e. ce_merge_base, cutting off commits aren't merged into
# EE yet. Here's an example:
#
# * o: Relevant commits
# * x: Irrelevant commits
# * !: Commits we want to cut off from CE branch
#
# ^-> o CE branch (ce_fetch_head)
# /
# o -> o -> ! -> x CE master
# v (ce_merge_base)
# o -> o -> o -> x EE master
# \ (ee_merge_base)
# v-> o EE branch
#
# We want to rebase above into this: (we only change the connection)
#
# -> - -> o CE branch (ce_fetch_head)
# /
# o -> o -> ! -> x CE master
# v (ce_merge_base)
# o -> o -> o -> x EE master
# \ (ee_merge_base)
# v-> o EE branch
#
# Therefore we rebase onto ce_merge_base, which is based off CE master,
# for the CE branch (ce_fetch_head), effective remove the commit marked
# as ! in the graph for CE branch. We need to remove it because it's not
# merged into EE yet, therefore won't be available in the EE branch.
#
# After rebase is done, then we could compare against
# ce_merge_base..ee_merge_base along with ce_fetch_head..HEAD (EE branch)
# where ce_merge_base..ee_merge_base is the update-to-date
# CE/EE difference and ce_fetch_head..HEAD is the changes we made in
# CE and EE branches.
run_git_command("rebase --onto #{ce_merge_base} canonical-ce/master #{ce_fetch_head}")
if status_clean?
head_commit_sha
else
say <<~MESSAGE
💥 WE HAVE CONFLICTS! This shouldn't happen. Please create an issue
💥 and ping @godfat to investigate.
MESSAGE
run_git_command("rebase --abort")
exit(255)
end
ensure # ensure would still run if we call exit, don't worry
# Make sure to switch back
run_git_command("checkout #{head}")
end
def head_commit_sha
run_git_command("rev-parse HEAD")
end
def status_clean?
run_git_command("status --porcelain") == ''
end
def remove_remotes def remove_remotes
run_git_command( run_git_command(
"remote remove canonical-ee", "remote remove canonical-ee",
...@@ -121,7 +194,7 @@ module EESpecificCheck ...@@ -121,7 +194,7 @@ module EESpecificCheck
commands.map do |cmd| commands.map do |cmd|
puts "=> Running `#{cmd}`" puts "=> Running `#{cmd}`"
`#{cmd}` `#{cmd}`.strip
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