Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7af585f1
Commit
7af585f1
authored
Sep 13, 2017
by
Valery Sizov
Committed by
Eric Eastwood
Sep 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fast forward merge: basic implemenation[ci skip]
parent
dede5f01
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
0 deletions
+94
-0
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-0
app/models/project.rb
app/models/project.rb
+17
-0
app/models/repository.rb
app/models/repository.rb
+19
-0
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+5
-0
app/services/merge_requests/ff_merge_service.rb
app/services/merge_requests/ff_merge_service.rb
+24
-0
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+5
-0
app/views/projects/_merge_request_merge_settings.html.haml
app/views/projects/_merge_request_merge_settings.html.haml
+22
-0
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-0
No files found.
app/controllers/projects_controller.rb
View file @
7af585f1
...
@@ -344,6 +344,7 @@ class ProjectsController < Projects::ApplicationController
...
@@ -344,6 +344,7 @@ class ProjectsController < Projects::ApplicationController
:tag_list
,
:tag_list
,
:visibility_level
,
:visibility_level
,
:template_name
,
:template_name
,
:merge_method
,
project_feature_attributes:
%i[
project_feature_attributes:
%i[
builds_access_level
builds_access_level
...
...
app/models/project.rb
View file @
7af585f1
...
@@ -1557,6 +1557,23 @@ class Project < ActiveRecord::Base
...
@@ -1557,6 +1557,23 @@ class Project < ActiveRecord::Base
persisted?
&&
path_changed?
persisted?
&&
path_changed?
end
end
def
merge_method
if
self
.
merge_requests_ff_only_enabled
:ff
else
:merge
end
end
def
merge_method
=
(
method
)
self
.
merge_requests_ff_only_enabled
=
method
.
to_s
==
"ff"
end
def
ff_merge_must_be_possible?
self
.
merge_requests_ff_only_enabled
end
# alias_method :merge_requests_ff_only_enabled?, :merge_requests_ff_only_enabled
private
private
def
storage
def
storage
...
...
app/models/repository.rb
View file @
7af585f1
...
@@ -854,6 +854,25 @@ class Repository
...
@@ -854,6 +854,25 @@ class Repository
end
end
end
end
def
ff_merge
(
user
,
source
,
target_branch
,
merge_request:
nil
)
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
if
source
.
is_a?
(
Gitlab
::
Git
::
Commit
)
source
.
raw_commit
else
rugged
.
lookup
(
source
)
end
raise
'Invalid merge target'
if
our_commit
.
nil?
raise
'Invalid merge source'
if
their_commit
.
nil?
with_branch
(
user
,
target_branch
)
do
|
start_commit
|
merge_request
&
.
update
(
in_progress_merge_commit_sha:
their_commit
.
oid
)
their_commit
.
oid
end
end
def
revert
(
def
revert
(
user
,
commit
,
branch_name
,
message
,
user
,
commit
,
branch_name
,
message
,
start_branch_name:
nil
,
start_project:
project
)
start_branch_name:
nil
,
start_project:
project
)
...
...
app/serializers/merge_request_entity.rb
View file @
7af585f1
...
@@ -13,6 +13,11 @@ class MergeRequestEntity < IssuableEntity
...
@@ -13,6 +13,11 @@ class MergeRequestEntity < IssuableEntity
expose
:target_branch
expose
:target_branch
expose
:target_project_id
expose
:target_project_id
expose
:ff_only_enabled
do
|
merge_request
|
merge_request
.
project
.
merge_requests_ff_only_enabled
end
# Events
# Events
expose
:merge_event
,
using:
EventEntity
expose
:merge_event
,
using:
EventEntity
expose
:closed_event
,
using:
EventEntity
expose
:closed_event
,
using:
EventEntity
...
...
app/services/merge_requests/ff_merge_service.rb
0 → 100644
View file @
7af585f1
module
MergeRequests
# MergeService class
#
# Do git fast-forward merge and in case of success
# mark merge request as merged and execute all hooks and notifications
# Executed when you do fast-forward merge via GitLab UI
#
class
FfMergeService
<
MergeRequests
::
MergeService
private
def
commit
repository
.
ff_merge
(
current_user
,
source
,
merge_request
.
target_branch
,
merge_request:
merge_request
)
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
e
raise
MergeError
,
e
.
message
rescue
StandardError
=>
e
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
ensure
merge_request
.
update
(
in_progress_merge_commit_sha:
nil
)
end
end
end
app/services/merge_requests/merge_service.rb
View file @
7af585f1
...
@@ -11,6 +11,11 @@ module MergeRequests
...
@@ -11,6 +11,11 @@ module MergeRequests
attr_reader
:merge_request
,
:source
attr_reader
:merge_request
,
:source
def
execute
(
merge_request
)
def
execute
(
merge_request
)
if
project
.
merge_requests_ff_only_enabled
&&
!
self
.
is_a?
(
FfMergeService
)
FfMergeService
.
new
(
project
,
current_user
,
params
).
execute
(
merge_request
)
return
end
@merge_request
=
merge_request
@merge_request
=
merge_request
unless
@merge_request
.
mergeable?
unless
@merge_request
.
mergeable?
...
...
app/views/projects/_merge_request_merge_settings.html.haml
View file @
7af585f1
-
form
=
local_assigns
.
fetch
(
:form
)
-
form
=
local_assigns
.
fetch
(
:form
)
.form-group
=
label_tag
:merge_method_merge
,
class:
'label-light'
do
Merge method
.radio
=
label_tag
:project_merge_method_merge
do
=
form
.
radio_button
:merge_method
,
:merge
,
class:
"js-merge-method-radio"
%strong
Merge commit
%br
%span
.descr
A merge commit is created for every merge, and merging is allowed as long as there are no conflicts.
.radio
=
label_tag
:project_merge_method_ff
do
=
form
.
radio_button
:merge_method
,
:ff
,
class:
"js-merge-method-radio"
%strong
Fast-forward merge
%br
%span
.descr
No merge commits are created and all merges are fast-forwarded, which means that merging is only allowed if the branch could be fast-forwarded.
%br
%span
.descr
When fast-forward merge is not possible, the user must first rebase locally.
.form-group
.form-group
.checkbox.builds-feature
{
class:
(
"hidden"
if
@project
&&
@project
.
project_feature
.
send
(
:builds_access_level
)
==
0
)
}
.checkbox.builds-feature
{
class:
(
"hidden"
if
@project
&&
@project
.
project_feature
.
send
(
:builds_access_level
)
==
0
)
}
=
form
.
label
:only_allow_merge_if_pipeline_succeeds
do
=
form
.
label
:only_allow_merge_if_pipeline_succeeds
do
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
7af585f1
...
@@ -412,6 +412,7 @@ Project:
...
@@ -412,6 +412,7 @@ Project:
-
last_repository_updated_at
-
last_repository_updated_at
-
ci_config_path
-
ci_config_path
-
delete_error
-
delete_error
-
merge_requests_ff_only_enabled
Author
:
Author
:
-
name
-
name
ProjectFeature
:
ProjectFeature
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment