Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Merge requests
!6949
Change the approach to check if patches apply cleanly
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Change the approach to check if patches apply cleanly
23372-fix-ce-to-ee-merge-check-task
into
master
Overview
18
Commits
4
Pipelines
22
Changes
5
All threads resolved!
Hide all comments
Merged
Rémy Coutable
requested to merge
23372-fix-ce-to-ee-merge-check-task
into
master
8 years ago
Overview
18
Commits
4
Pipelines
22
Changes
4
All threads resolved!
Hide all comments
Expand
What does this MR do?
Are there points in the code the reviewer needs to double check?
Why was this MR needed?
Screenshots (if relevant)
Does this MR meet the acceptance criteria?
CHANGELOG
entry added
Documentation created/updated
API support added
Tests
Added for this feature/bug
All builds are passing
Conform by the
merge request performance guides
Conform by the
style guides
Branch has no merge conflicts with
master
(if it does - rebase it please)
Squashed related commits together
What are the relevant issue numbers?
Closes
#23372 (closed)
0
0
Merge request reports
Compare
version 7
version 22
402dcab4
8 years ago
version 21
c7af4cf8
8 years ago
version 20
c7af4cf8
8 years ago
version 19
c7af4cf8
8 years ago
version 18
c7af4cf8
8 years ago
version 17
af669cbe
8 years ago
version 16
12115682
8 years ago
version 15
b433422e
8 years ago
version 14
a09fefd4
8 years ago
version 13
cd4ab7ef
8 years ago
version 12
02226a83
8 years ago
version 11
82f2ef10
8 years ago
version 10
19259697
8 years ago
version 9
5a3bf61e
8 years ago
version 8
04754e5e
8 years ago
version 7
157a53e6
8 years ago
version 6
bd03f891
8 years ago
version 5
bd03f891
8 years ago
version 4
a5097540
8 years ago
version 3
a5097540
8 years ago
version 2
a5097540
8 years ago
version 1
c5d3bf5b
8 years ago
master (base)
and
version 14
latest version
d38d4a9e
4 commits,
8 years ago
version 22
402dcab4
3 commits,
8 years ago
version 21
c7af4cf8
2 commits,
8 years ago
version 20
c7af4cf8
2 commits,
8 years ago
version 19
c7af4cf8
2 commits,
8 years ago
version 18
c7af4cf8
2 commits,
8 years ago
version 17
af669cbe
1 commit,
8 years ago
version 16
12115682
1 commit,
8 years ago
version 15
b433422e
1 commit,
8 years ago
version 14
a09fefd4
6 commits,
8 years ago
version 13
cd4ab7ef
6 commits,
8 years ago
version 12
02226a83
6 commits,
8 years ago
version 11
82f2ef10
5 commits,
8 years ago
version 10
19259697
5 commits,
8 years ago
version 9
5a3bf61e
4 commits,
8 years ago
version 8
04754e5e
4 commits,
8 years ago
version 7
157a53e6
4 commits,
8 years ago
version 6
bd03f891
3 commits,
8 years ago
version 5
bd03f891
3 commits,
8 years ago
version 4
a5097540
2 commits,
8 years ago
version 3
a5097540
2 commits,
8 years ago
version 2
a5097540
2 commits,
8 years ago
version 1
c5d3bf5b
1 commit,
8 years ago
Show latest version
4 files
+
290
−
445
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
lib/gitlab/ee_compat_check.rb
0 → 100644
+
273
−
0
Options
module
Gitlab
# Checks if a set of migrations requires downtime or not.
class
EeCompatCheck
EE_REPO
=
'https://gitlab.com/gitlab-org/gitlab-ee.git'
.
freeze
attr_reader
:ce_branch
,
:check_dir
,
:ce_repo
def
initialize
(
branch
:,
check_dir
:,
ce_repo:
nil
)
@ce_branch
=
branch
@check_dir
=
check_dir
@ce_repo
=
ce_repo
||
'https://gitlab.com/gitlab-org/gitlab-ce.git'
end
def
check
ensure_ee_repo
delete_patches
generate_patch
(
ce_branch
,
ce_patch_full_path
)
Dir
.
chdir
(
check_dir
)
do
step
(
"In the
#{
check_dir
}
directory"
)
step
(
"Pulling latest master"
,
%w[git pull --ff-only origin master]
)
status
=
catch
(
:halt_check
)
do
ce_branch_compat_check!
delete_ee_branch_locally
ee_branch_presence_check!
ee_branch_compat_check!
end
delete_ee_branch_locally
delete_patches
if
status
.
nil?
puts
puts
ee_applies_cleanly_msg
true
else
false
end
end
end
private
def
ensure_ee_repo
if
Dir
.
exist?
(
check_dir
)
step
(
"
#{
check_dir
}
already exists"
)
else
cmd
=
%W[git clone --branch master --single-branch --depth 1
#{
EE_REPO
}
#{
check_dir
}
]
step
(
"Cloning
#{
EE_REPO
}
into
#{
check_dir
}
"
,
cmd
)
end
end
def
ce_branch_compat_check!
cmd
=
%W[git apply --check
#{
ce_patch_full_path
}
]
status
=
step
(
"Checking if
#{
ce_patch_name
}
applies cleanly to EE/master"
,
cmd
)
if
status
.
zero?
puts
ce_applies_cleanly_msg
(
ce_branch
)
throw
(
:halt_check
)
end
end
def
ee_branch_presence_check!
status
=
step
(
"Fetching origin/
#{
ee_branch
}
"
,
%W[git fetch origin
#{
ee_branch
}
]
)
unless
status
.
zero?
puts
puts
ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg
throw
(
:halt_check
,
:ko
)
end
end
def
ee_branch_compat_check!
step
(
"Checking out origin/
#{
ee_branch
}
"
,
%W[git checkout -b
#{
ee_branch
}
FETCH_HEAD]
)
generate_patch
(
ee_branch
,
ee_patch_full_path
)
cmd
=
%W[git apply --check
#{
ee_patch_full_path
}
]
status
=
step
(
"Checking if
#{
ee_patch_name
}
applies cleanly to EE/master"
,
cmd
)
unless
status
.
zero?
puts
puts
ee_branch_doesnt_apply_cleanly_msg
throw
(
:halt_check
,
:ko
)
end
end
def
generate_patch
(
branch
,
filepath
)
FileUtils
.
rm
(
filepath
,
force:
true
)
depth
=
0
loop
do
depth
+=
10
step
(
"Fetching origin/master"
,
%W[git fetch origin master --depth=
#{
depth
}
]
)
status
=
step
(
"Finding merge base with master"
,
%W[git merge-base FETCH_HEAD
#{
branch
}
]
)
break
if
status
.
zero?
||
depth
>
500
end
raise
"
#{
branch
}
is too far behind master, please rebase it!"
if
depth
>
500
step
(
"Generating the patch against master"
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
%w[git format-patch FETCH_HEAD --stdout]
)
throw
(
:halt_check
,
:ko
)
unless
status
.
zero?
File
.
open
(
filepath
,
'w+'
)
{
|
f
|
f
.
write
(
output
)
}
throw
(
:halt_check
,
:ko
)
unless
File
.
exist?
(
filepath
)
end
def
delete_ee_branch_locally
step
(
"Checking out origin/master"
,
%w[git checkout master]
)
step
(
"Deleting the local
#{
ee_branch
}
branch"
,
%W[git branch -D
#{
ee_branch
}
]
)
end
def
delete_patches
step
(
"Deleting
#{
ce_patch_full_path
}
"
)
FileUtils
.
rm
(
ce_patch_full_path
,
force:
true
)
step
(
"Deleting
#{
ee_patch_full_path
}
"
)
FileUtils
.
rm
(
ee_patch_full_path
,
force:
true
)
end
def
ce_patch_name
@ce_patch_name
||=
"
#{
ce_branch
}
.patch"
end
def
ce_patch_full_path
@ce_patch_full_path
||=
File
.
expand_path
(
ce_patch_name
,
check_dir
)
end
def
ee_branch
@ee_branch
||=
"
#{
ce_branch
}
-ee"
end
def
ee_patch_name
@ee_patch_name
||=
"
#{
ee_branch
}
.patch"
end
def
ee_patch_full_path
@ee_patch_full_path
||=
File
.
expand_path
(
ee_patch_name
,
check_dir
)
end
def
step
(
desc
,
cmd
=
nil
)
puts
"
\n
=>
#{
desc
}
\n
"
if
cmd
puts
"
\n
$
#{
cmd
.
join
(
' '
)
}
"
command
(
cmd
)
end
end
def
command
(
cmd
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
puts
output
status
end
def
ce_applies_cleanly_msg
(
ce_branch
)
<<-
MSG
.
strip_heredoc
=================================================================
🎉 Congratulations!! 🎉
The
#{
ce_branch
}
branch applies cleanly to EE/master!
Much ❤️!!
=================================================================
\n
MSG
end
def
ce_branch_doesnt_apply_cleanly_and_no_ee_branch_msg
<<-
MSG
.
strip_heredoc
=================================================================
💥 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.
Please create a
#{
ee_branch
}
branch that includes changes from
#{
ce_branch
}
but also specific changes than can be applied cleanly
to EE/master.
There are different ways to create such branch:
1. Create a new branch based on the CE branch and rebase it on top of EE/master
# In the EE repo
$ git fetch
#{
ce_repo
}
#{
ce_branch
}
$ git checkout -b
#{
ee_branch
}
FETCH_HEAD
# You can squash the
#{
ce_branch
}
commits into a single "Port of
#{
ce_branch
}
to EE" commit
# before rebasing to limit the conflicts-resolving steps during the rebase
$ git fetch origin
$ git rebase origin/master
At this point you will likely have conflicts.
Solve them, and continue/finish the rebase.
You can squash the
#{
ce_branch
}
commits into a single "Port of
#{
ce_branch
}
to EE".
2. Create a new branch from master and cherry-pick your CE commits
# In the EE repo
$ git fetch origin
$ git checkout -b
#{
ee_branch
}
FETCH_HEAD
$ git fetch
#{
ce_repo
}
#{
ce_branch
}
$ git cherry-pick SHA # Repeat for all the commits you want to pick
You can squash the
#{
ce_branch
}
commits into a single "Port of
#{
ce_branch
}
to EE" commit.
3. Generate a patch from your CE branch and apply it in a new EE branch
# In the CE repo
$ git fetch origin master
$ git format-patch FETCH_HEAD --stdout > ~/
#{
ce_branch
}
.patch
# In the EE repo
$ git fetch origin master
$ git checkout -b
#{
ee_branch
}
FETCH_HEAD
$ git apply ~/
#{
ce_branch
}
.patch
At this point you will likely have conflicts.
Solve them, and create a new "Port of
#{
ce_branch
}
to EE" commit.
Don't forget to push your branch to
#{
EE_REPO
}
:
# In the EE repo
$ git push origin
#{
ee_branch
}
You can then retry this failed build, and hopefully it should pass.
Stay 💪 !
=================================================================
\n
MSG
end
def
ee_branch_doesnt_apply_cleanly_msg
<<-
MSG
.
strip_heredoc
=================================================================
💥 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
repository, it does not apply cleanly either to EE/master!
Please update the
#{
ee_branch
}
, push it again to
#{
EE_REPO
}
, and
retry this build.
Stay 💪 !
=================================================================
\n
MSG
end
def
ee_applies_cleanly_msg
<<-
MSG
.
strip_heredoc
=================================================================
🎉 Congratulations!! 🎉
The
#{
ee_branch
}
branch applies cleanly to EE/master!
Much ❤️!!
=================================================================
\n
MSG
end
end
end
Loading