Commit 02379ce8 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ee-5960-do-not-rebase-if-no-needed' into 'master'

Don't rebase if not needed in ee-specific-lines-check

See merge request gitlab-org/gitlab-ee!5698
parents 32c954bb d2e73457
......@@ -8,7 +8,7 @@ git_version
base = find_compare_base
new_files_in_this_branch_not_at_the_ee_top_level =
run_git_command("diff #{base.ee_merge_base}...HEAD --name-status --diff-filter=A -- ./ ':!ee' | cut -f2").lines.map(&:strip)
run_git_command("diff #{base.ee_fetch_base}...HEAD --name-status --diff-filter=A -- ./ ':!ee' | cut -f2").lines.map(&:strip)
ee_specific_files_in_ce_master_not_at_the_ee_top_level =
run_git_command("diff #{base.ce_updated_base}..HEAD --name-status --diff-filter=A -- ./ ':!ee' | cut -f2").lines.map(&:strip)
......
......@@ -7,7 +7,7 @@ git_version
base = find_compare_base
current_numstat = updated_diff_numstat(base.ce_merge_base, base.ee_merge_base)
current_numstat = updated_diff_numstat(base.ce_merge_base, base.ee_fetch_base)
updated_numstat = updated_diff_numstat(base.ce_updated_base, 'HEAD')
offenses = updated_numstat.select do |file, updated_delta|
......
......@@ -14,7 +14,7 @@ module EESpecificCheck
'locale/gitlab.pot'
].freeze
CompareBase = Struct.new(:ce_merge_base, :ee_merge_base, :ce_updated_base)
CompareBase = Struct.new(:ce_merge_base, :ee_fetch_base, :ce_updated_base)
module_function
......@@ -27,27 +27,25 @@ module EESpecificCheck
end
def find_compare_base
# We're still seeing errors not ignoring knapsack/ and rspec_flaky/
# Instead of waiting that populate over all the branches, we could
# just remove untracked files anyway, only on CI of course in case
# we're wiping people's data!
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/5912
git_clean if ENV['CI']
git_clean
setup_canonical_remotes
ce_fetch_head = fetch_remote_ce_branch
ce_fetch_base = run_git_command("merge-base canonical-ce/master #{ce_fetch_head}")
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")
ee_fetch_base = run_git_command("merge-base canonical-ee/master HEAD")
ce_updated_base =
if ce_fetch_head.start_with?('canonical-ce')
ce_merge_base # Compare with merge-base if no specific CE branch
if ce_fetch_head.start_with?('canonical-ce') || # No specific CE branch
ce_fetch_base == ce_merge_base # Up-to-date, no rebase needed
ce_merge_base
else
checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(ce_merge_base, ce_fetch_head)
checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(
ce_fetch_head, ce_fetch_base, ce_merge_base)
end
CompareBase.new(ce_merge_base, ee_merge_base, ce_updated_base)
CompareBase.new(ce_merge_base, ee_fetch_base, ce_updated_base)
end
def setup_canonical_remotes
......@@ -66,12 +64,14 @@ module EESpecificCheck
"#{remote_to_fetch}/#{branch_to_fetch}"
end
def checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(ce_merge_base, ce_fetch_head)
def checkout_and_rebase_ce_fetch_head_onto_ce_merge_base(
ce_fetch_head, ce_fetch_base, ce_merge_base)
# 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}")
run_git_command("checkout -f #{ce_fetch_head}")
git_clean
# 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
......@@ -82,21 +82,21 @@ module EESpecificCheck
# * !: Commits we want to cut off from CE branch
#
# ^-> o CE branch (ce_fetch_head)
# /
# / (ce_fetch_base)
# o -> o -> ! -> x CE master
# v (ce_merge_base)
# o -> o -> o -> x EE master
# \ (ee_merge_base)
# \ (ee_fetch_base)
# v-> o EE branch
#
# We want to rebase above into this: (we only change the connection)
#
# -> - -> o CE branch (ce_fetch_head)
# /
# / (ce_fetch_base)
# o -> o -> ! -> x CE master
# v (ce_merge_base)
# o -> o -> o -> x EE master
# \ (ee_merge_base)
# \ (ee_fetch_base)
# v-> o EE branch
#
# Therefore we rebase onto ce_merge_base, which is based off CE master,
......@@ -105,12 +105,11 @@ module EESpecificCheck
# 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_merge_base..ee_fetch_base along with ce_fetch_head..HEAD (EE branch)
# where ce_merge_base..ee_fetch_base is the update-to-date
# CE/EE difference and ce_fetch_head..HEAD is the changes we made in
# CE and EE branches.
old_base = run_git_command("merge-base canonical-ce/master #{ce_fetch_head}")
run_git_command("rebase --onto #{ce_merge_base} #{old_base}~1 #{ce_fetch_head}")
run_git_command("rebase --onto #{ce_merge_base} #{ce_fetch_base}~1 #{ce_fetch_head}")
status = git_status
......@@ -133,7 +132,8 @@ module EESpecificCheck
ensure # ensure would still run if we call exit, don't worry
# Make sure to switch back
run_git_command("checkout #{head}")
run_git_command("checkout -f #{head}")
git_clean
end
def head_commit_sha
......@@ -145,7 +145,13 @@ module EESpecificCheck
end
def git_clean
run_git_command('clean -fd')
# We're still seeing errors not ignoring knapsack/ and rspec_flaky/
# Instead of waiting that populate over all the branches, we could
# just remove untracked files anyway, only on CI of course in case
# we're wiping people's data!
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/5912
# Also see https://gitlab.com/gitlab-org/gitlab-ee/-/jobs/68194333
run_git_command('clean -fd') if ENV['CI']
end
def remove_remotes
......
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