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 ...@@ -8,7 +8,7 @@ git_version
base = find_compare_base base = find_compare_base
new_files_in_this_branch_not_at_the_ee_top_level = 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 = 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) 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 ...@@ -7,7 +7,7 @@ git_version
base = find_compare_base 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') updated_numstat = updated_diff_numstat(base.ce_updated_base, 'HEAD')
offenses = updated_numstat.select do |file, updated_delta| offenses = updated_numstat.select do |file, updated_delta|
......
...@@ -14,7 +14,7 @@ module EESpecificCheck ...@@ -14,7 +14,7 @@ module EESpecificCheck
'locale/gitlab.pot' 'locale/gitlab.pot'
].freeze ].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 module_function
...@@ -27,27 +27,25 @@ module EESpecificCheck ...@@ -27,27 +27,25 @@ module EESpecificCheck
end end
def find_compare_base def find_compare_base
# We're still seeing errors not ignoring knapsack/ and rspec_flaky/ git_clean
# 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']
setup_canonical_remotes setup_canonical_remotes
ce_fetch_head = fetch_remote_ce_branch 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") 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 = ce_updated_base =
if ce_fetch_head.start_with?('canonical-ce') if ce_fetch_head.start_with?('canonical-ce') || # No specific CE branch
ce_merge_base # Compare with merge-base if no specific CE branch ce_fetch_base == ce_merge_base # Up-to-date, no rebase needed
ce_merge_base
else 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 end
CompareBase.new(ce_merge_base, ee_merge_base, ce_updated_base) CompareBase.new(ce_merge_base, ee_fetch_base, ce_updated_base)
end end
def setup_canonical_remotes def setup_canonical_remotes
...@@ -66,12 +64,14 @@ module EESpecificCheck ...@@ -66,12 +64,14 @@ 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) 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 # So that we could switch back
head = head_commit_sha head = head_commit_sha
# Use detached HEAD so that we don't update HEAD # 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 # 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 # CE and EE, i.e. ce_merge_base, cutting off commits aren't merged into
...@@ -82,21 +82,21 @@ module EESpecificCheck ...@@ -82,21 +82,21 @@ module EESpecificCheck
# * !: Commits we want to cut off from CE branch # * !: Commits we want to cut off from CE branch
# #
# ^-> o CE branch (ce_fetch_head) # ^-> o CE branch (ce_fetch_head)
# / # / (ce_fetch_base)
# o -> o -> ! -> x CE master # o -> o -> ! -> x CE master
# v (ce_merge_base) # v (ce_merge_base)
# o -> o -> o -> x EE master # o -> o -> o -> x EE master
# \ (ee_merge_base) # \ (ee_fetch_base)
# v-> o EE branch # v-> o EE branch
# #
# We want to rebase above into this: (we only change the connection) # We want to rebase above into this: (we only change the connection)
# #
# -> - -> o CE branch (ce_fetch_head) # -> - -> o CE branch (ce_fetch_head)
# / # / (ce_fetch_base)
# o -> o -> ! -> x CE master # o -> o -> ! -> x CE master
# v (ce_merge_base) # v (ce_merge_base)
# o -> o -> o -> x EE master # o -> o -> o -> x EE master
# \ (ee_merge_base) # \ (ee_fetch_base)
# v-> o EE branch # v-> o EE branch
# #
# Therefore we rebase onto ce_merge_base, which is based off CE master, # Therefore we rebase onto ce_merge_base, which is based off CE master,
...@@ -105,12 +105,11 @@ module EESpecificCheck ...@@ -105,12 +105,11 @@ module EESpecificCheck
# merged into EE yet, therefore won't be available in the EE branch. # merged into EE yet, therefore won't be available in the EE branch.
# #
# After rebase is done, then we could compare against # After rebase is done, then we could compare against
# ce_merge_base..ee_merge_base along with ce_fetch_head..HEAD (EE branch) # ce_merge_base..ee_fetch_base along with ce_fetch_head..HEAD (EE branch)
# where ce_merge_base..ee_merge_base is the update-to-date # 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/EE difference and ce_fetch_head..HEAD is the changes we made in
# CE and EE branches. # 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} #{ce_fetch_base}~1 #{ce_fetch_head}")
run_git_command("rebase --onto #{ce_merge_base} #{old_base}~1 #{ce_fetch_head}")
status = git_status status = git_status
...@@ -133,7 +132,8 @@ module EESpecificCheck ...@@ -133,7 +132,8 @@ module EESpecificCheck
ensure # ensure would still run if we call exit, don't worry ensure # ensure would still run if we call exit, don't worry
# Make sure to switch back # Make sure to switch back
run_git_command("checkout #{head}") run_git_command("checkout -f #{head}")
git_clean
end end
def head_commit_sha def head_commit_sha
...@@ -145,7 +145,13 @@ module EESpecificCheck ...@@ -145,7 +145,13 @@ module EESpecificCheck
end end
def git_clean 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 end
def remove_remotes 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