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
88115792
Commit
88115792
authored
Aug 27, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement fast-forward merge
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
584ff6f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
3 deletions
+72
-3
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+14
-1
app/models/repository.rb
app/models/repository.rb
+12
-0
app/services/merge_requests/ff_merge_service.rb
app/services/merge_requests/ff_merge_service.rb
+38
-0
app/views/projects/merge_requests/ff_merge.js.haml
app/views/projects/merge_requests/ff_merge.js.haml
+6
-0
app/views/projects/merge_requests/widget/open/_ff_accept.html.haml
.../projects/merge_requests/widget/open/_ff_accept.html.haml
+2
-2
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
88115792
...
@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action
:module_enabled
before_action
:module_enabled
before_action
:merge_request
,
only:
[
before_action
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:merge
,
:merge_check
,
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:merge
,
:merge_check
,
:ci_status
,
:toggle_subscription
,
:approve
:ci_status
,
:toggle_subscription
,
:approve
,
:ff_merge
]
]
before_action
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
]
before_action
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
]
...
@@ -218,6 +218,19 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -218,6 +218,19 @@ class Projects::MergeRequestsController < Projects::ApplicationController
redirect_to
merge_request_path
(
@merge_request
)
redirect_to
merge_request_path
(
@merge_request
)
end
end
def
ff_merge
return
access_denied!
unless
@merge_request
.
can_be_merged_by?
(
current_user
)
return
render_404
unless
@merge_request
.
approved?
if
@merge_request
.
ff_merge_possible?
MergeRequests
::
FfMergeService
.
new
(
merge_request
.
target_project
,
current_user
).
execute
(
merge_request
)
@status
=
true
else
@status
=
false
end
end
protected
protected
def
selected_target_project
def
selected_target_project
...
...
app/models/repository.rb
View file @
88115792
...
@@ -435,6 +435,18 @@ class Repository
...
@@ -435,6 +435,18 @@ class Repository
end
end
end
end
def
ff_merge
(
user
,
source_sha
,
target_branch
,
options
=
{})
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
rugged
.
lookup
(
source_sha
)
raise
"Invalid merge target"
if
our_commit
.
nil?
raise
"Invalid merge source"
if
their_commit
.
nil?
commit_with_hooks
(
user
,
target_branch
)
do
|
ref
|
source_sha
end
end
def
merge
(
user
,
source_sha
,
target_branch
,
options
=
{})
def
merge
(
user
,
source_sha
,
target_branch
,
options
=
{})
our_commit
=
rugged
.
branches
[
target_branch
].
target
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
rugged
.
lookup
(
source_sha
)
their_commit
=
rugged
.
lookup
(
source_sha
)
...
...
app/services/merge_requests/ff_merge_service.rb
0 → 100644
View file @
88115792
module
MergeRequests
# MergeService class
#
# Do git merge and in case of success
# mark merge request as merged and execute all hooks and notifications
# Executed when you do merge via GitLab UI
#
class
FfMergeService
<
MergeRequests
::
BaseService
attr_reader
:merge_request
def
execute
(
merge_request
)
@merge_request
=
merge_request
unless
@merge_request
.
ff_merge_possible?
return
error
(
'Merge request is not mergeable'
)
end
merge_request
.
in_locked_state
do
if
update_head
after_merge
success
else
error
(
'Can not merge changes'
)
end
end
end
private
def
update_head
repository
.
ff_merge
(
current_user
,
merge_request
.
source_sha
,
merge_request
.
target_branch
)
end
def
after_merge
MergeRequests
::
PostMergeService
.
new
(
project
,
current_user
).
execute
(
merge_request
)
end
end
end
app/views/projects/merge_requests/ff_merge.js.haml
0 → 100644
View file @
88115792
-
if
@status
:plain
location.reload()
-
else
:plain
$('.mr-widget-body').html("
#{
escape_javascript
(
render
(
'projects/merge_requests/widget/open/reload'
))
}
");
app/views/projects/merge_requests/widget/open/_ff_accept.html.haml
View file @
88115792
...
@@ -17,8 +17,8 @@
...
@@ -17,8 +17,8 @@
.accept-action
.accept-action
=
f
.
button
class:
"btn btn-reopen rebase-mr"
do
=
f
.
button
class:
"btn btn-reopen rebase-mr"
do
Rebase from
#{
@merge_request
.
target_branch
}
Rebase from
#{
@merge_request
.
target_branch
}
.accept-control
.accept-control
Fast-forward merge is not possible. Branch must be rebased first
Fast-forward merge is not possible. Branch must be rebased first
:coffeescript
:coffeescript
$('.accept-mr-form').on 'ajax:before', ->
$('.accept-mr-form').on 'ajax:before', ->
...
...
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