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
34457b30
Commit
34457b30
authored
Sep 02, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement rebase feature
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
b8540106
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
2 deletions
+64
-2
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+9
-1
app/services/merge_requests/rebase_service.rb
app/services/merge_requests/rebase_service.rb
+54
-0
app/views/projects/merge_requests/widget/open/_ff_accept.html.haml
.../projects/merge_requests/widget/open/_ff_accept.html.haml
+1
-1
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
34457b30
...
...
@@ -2,7 +2,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action
:module_enabled
before_action
:merge_request
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
,
:merge
,
:merge_check
,
:ci_status
,
:toggle_subscription
,
:approve
,
:ff_merge
:ci_status
,
:toggle_subscription
,
:approve
,
:ff_merge
,
:rebase
]
before_action
:closes_issues
,
only:
[
:edit
,
:update
,
:show
,
:diffs
,
:commits
]
before_action
:validates_merge_request
,
only:
[
:show
,
:diffs
,
:commits
]
...
...
@@ -231,6 +231,14 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
def
rebase
return
access_denied!
unless
@merge_request
.
can_be_merged_by?
(
current_user
)
return
render_404
unless
@merge_request
.
approved?
MergeRequests
::
RebaseService
.
new
(
merge_request
.
target_project
,
current_user
).
execute
(
merge_request
)
end
protected
def
selected_target_project
...
...
app/services/merge_requests/rebase_service.rb
0 → 100644
View file @
34457b30
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
RebaseService
<
MergeRequests
::
BaseService
include
Gitlab
::
Popen
attr_reader
:merge_request
def
execute
(
merge_request
)
@merge_request
=
merge_request
if
rebase
success
else
error
(
'Failed to rebase. Should be done manually'
)
end
end
def
rebase
Gitlab
::
ShellEnv
.
set_env
(
current_user
)
# Clone
output
,
status
=
popen
(
%W(git clone -b
#{
merge_request
.
source_branch
}
--
#{
source_project
.
repository
.
path_to_repo
}
#{
tree_path
}
)
)
raise
'Failed to clone repo'
unless
status
.
zero?
# Rebase
output
,
status
=
popen
(
%W(git pull --rebase
#{
target_project
.
repository
.
path_to_repo
}
#{
merge_request
.
target_branch
}
)
,
tree_path
)
raise
'Failed to rebase'
unless
status
.
zero?
output
,
status
=
popen
(
%W(git push -f origin
#{
merge_request
.
source_branch
}
)
,
tree_path
)
raise
'Failed to push'
unless
status
.
zero?
true
ensure
Gitlab
::
ShellEnv
.
reset_env
end
def
source_project
@source_project
||=
merge_request
.
source_project
end
def
target_project
@target_project
||=
merge_request
.
target_project
end
def
tree_path
@tree_path
||=
Rails
.
root
.
join
(
'tmp'
,
'rebase'
,
source_project
.
id
.
to_s
,
SecureRandom
.
hex
).
to_s
end
end
end
app/views/projects/merge_requests/widget/open/_ff_accept.html.haml
View file @
34457b30
...
...
@@ -10,7 +10,7 @@
Fast-forward merge without creating merge commit
-
else
=
form_for
[
:rebase
,
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@merge_request
],
remote:
tru
e
,
method: :post
,
html:
{
class:
'accept-mr-form js-requires-input'
}
do
|
f
|
remote:
fals
e
,
method: :post
,
html:
{
class:
'accept-mr-form js-requires-input'
}
do
|
f
|
=
hidden_field_tag
:authenticity_token
,
form_authenticity_token
.accept-merge-holder.clearfix.js-toggle-container
-
if
@merge_request
.
target_project
.
merge_requests_rebase_enabled
&&
can_rebase?
(
@merge_request
.
target_project
,
@merge_request
.
target_branch
)
...
...
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