Skip to content
Snippets Groups Projects

Change the approach to check if patches apply cleanly

Merged Rémy Coutable requested to merge 23372-fix-ce-to-ee-merge-check-task into master
All threads resolved!
Compare and Show latest version
2 files
+ 43
142
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 43
30
@@ -6,7 +6,7 @@ namespace :gitlab do
return unless ENV['CI']
ce_repo = ENV['CI_BUILD_REPO'] || 'https://gitlab.com/gitlab-org/gitlab-ce.git'
ce_branch = ENV['CI_BUILD_REF_NAME'] || 'find-file-enter-fix'# run_command(%w[git rev-parse --abbrev-ref HEAD]).chomp
ce_branch = ENV['CI_BUILD_REF_NAME'] || run_command(%w[git rev-parse --abbrev-ref HEAD]).chomp
ce_patch_name = "#{ce_branch}.patch"
ee_repo = 'https://gitlab.com/gitlab-org/gitlab-ee.git'
@@ -14,28 +14,38 @@ namespace :gitlab do
ee_patch_name = "#{ee_branch}.patch"
ee_dir = 'gitlab-ee-merge-check'
clean_dir(ee_dir)
cmd = %W[git clone --branch master --single-branch --depth 1 #{ee_repo} #{ee_dir}]
step("Cloning #{ee_repo} into #{ee_dir}", cmd)
if Dir.exists?(ee_repo)
step("#{ee_dir} already exists")
else
cmd = %W[git clone --branch master --single-branch --depth 1 #{ee_repo} #{ee_dir}]
step("Cloning #{ee_repo} into #{ee_dir}", cmd)
end
cmd = %W[git format-patch master --stdout > ./#{ee_dir}/#{ce_patch_name}]
FileUtils.rm("./#{ee_dir}/#{ce_patch_name}", force: true)
step("Fetching origin/master", %w[git fetch origin master])
cmd = %W[git format-patch FETCH_HEAD --stdout > ./#{ee_dir}/#{ce_patch_name}]
step("Generating the patch against master for #{ce_branch}", cmd)
Dir.chdir(ee_dir) do
step("In the #{run_command(%w[pwd]).chomp} directory")
step("Pulling latest master", %w[git pull --ff-only origin master])
# Check if the CE-branch patch applies cleanly to EE/master...
cmd = %W[git apply --check #{ce_patch_name}]
status = step("Checking if #{ce_patch_name} applies cleanly to EE/master", cmd)
puts ce_applies_cleanly_msg(ce_branch) if status.zero?
if status.zero?
puts ce_applies_cleanly_msg(ce_branch)
exit 0
end
# Check if the <branch>-ee branch exists...
command(%W[git fetch origin #{ee_branch}])
status = step("Fetching origin/#{ee_branch}", %W[git fetch origin #{ee_branch}])
cmd = %W[git checkout #{ee_branch}]
status = step("Checking out the #{ee_branch} branch", cmd)
# cmd = %W[git checkout -b #{ee_branch} FETCH_HEAD]
# status = step("Checking out the #{ee_branch} branch", cmd)
# The <branch>-ee doesn't exist
unless status.zero?
@@ -50,40 +60,43 @@ namespace :gitlab do
exit 1
end
# Check if the EE-branch patch applies cleanly to EE/master...
command(%W[git format-patch master --stdout > #{ee_patch_name}])
cmd = %W[git apply --check #{ee_patch_name}]
status = step("Checking if #{ee_patch_name} applies cleanly to EE/master", cmd)
# The <branch>-ee cannot be merged cleanly to EE/master...
unless status.zero?
puts
puts ee_branch_doesnt_apply_cleanly_msg(
ce_branch: ce_branch,
ee_repo: ee_repo,
ee_branch: ee_branch
)
exit 2
end
# # Check if the EE-branch patch applies cleanly to EE/master...
# # Does it really make sense? Won't an EE patch always apply to EE/master???????
# FileUtils.rm(ee_patch_name, force: true)
# command(%W[git format-patch origin/master --stdout > #{ee_patch_name}])
# cmd = %W[git apply --check #{ee_patch_name}]
# status = step("Checking if #{ee_patch_name} applies cleanly to EE/master", cmd)
#
# # The <branch>-ee cannot be merged cleanly to EE/master...
# unless status.zero?
# puts
# puts ee_branch_doesnt_apply_cleanly_msg(
# ce_branch: ce_branch,
# ee_repo: ee_repo,
# ee_branch: ee_branch
# )
#
# clean_dir_and_exit(ee_dir, 2)
# end
puts
puts ee_applies_cleanly_msg(ee_branch: ee_branch)
end
clean_dir(ee_dir)
exit 0
end
def clean_dir(dir)
def clean_dir_and_exit(dir, status = 0)
FileUtils.rm_rf(dir)
exit status
end
def step(desc, cmd = nil)
puts "\n=> #{desc}\n"
if cmd
puts "\n==> #{cmd.join(' ')}"
puts "\n$ #{cmd.join(' ')}"
command(cmd)
end
end
@@ -110,7 +123,7 @@ namespace :gitlab do
def ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg(ce_repo:, ce_branch:, ee_repo:, ee_branch:)
<<-MSG.strip_heredoc
=================================================================
💥 Oh no! 💥
💥 Oh no! 💥
The #{ce_branch} branch does not apply cleanly to the current
EE/master, and no #{ee_branch} branch was found in the EE repository.
@@ -148,7 +161,7 @@ namespace :gitlab do
def ee_branch_doesnt_apply_cleanly_msg(ce_branch:, ee_repo:, ee_branch:)
<<-MSG.strip_heredoc
=================================================================
💥 Oh no! 💥
💥 Oh no! 💥
The #{ce_branch} does not apply cleanly to the current
EE/master, and even though a #{ee_branch} branch exists in the EE
Loading