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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
f56ee9d3
Commit
f56ee9d3
authored
Jan 29, 2016
by
Rubén Dávila
Committed by
Robert Speicher
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save merge commit id when MR is merged
parent
720e52d9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
5 deletions
+37
-5
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/repository.rb
app/models/repository.rb
+27
-3
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+2
-1
db/migrate/20160129155512_add_merge_commit_sha_to_merge_requests.rb
.../20160129155512_add_merge_commit_sha_to_merge_requests.rb
+5
-0
spec/factories/merge_requests.rb
spec/factories/merge_requests.rb
+1
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+1
-0
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
f56ee9d3
...
...
@@ -193,7 +193,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def
revert
@repository
.
find_or_create_branch
(
@merge_request
.
reverse_branch_name
,
@merge_request
.
target_branch
)
@repository
.
revert_merge
(
current_user
,
@merge_request
.
merge_commit_sha
,
@merge_request
.
reverse_branch_name
)
url_params
=
{
merge_request:
{
source_branch:
@merge_request
.
reverse_branch_name
,
...
...
app/models/repository.rb
View file @
f56ee9d3
...
...
@@ -137,8 +137,8 @@ class Repository
find_branch
(
branch_name
)
end
def
find_or_create_branch
(
name
,
ref
)
find_branch
(
name
)
or
add_branch
(
name
,
ref
)
def
find_or_create_branch
(
user
,
name
,
ref
)
find_branch
(
name
)
or
add_branch
(
user
,
name
,
ref
)
end
def
add_tag
(
tag_name
,
ref
,
message
=
nil
)
...
...
@@ -605,6 +605,7 @@ class Repository
def
merge
(
user
,
source_sha
,
target_branch
,
options
=
{})
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
rugged
.
lookup
(
source_sha
)
merge_commit_sha
=
nil
raise
"Invalid merge target"
if
our_commit
.
nil?
raise
"Invalid merge source"
if
their_commit
.
nil?
...
...
@@ -619,8 +620,31 @@ class Repository
update_ref:
ref
)
Rugged
::
Commit
.
create
(
rugged
,
actual_options
)
merge_commit_sha
=
Rugged
::
Commit
.
create
(
rugged
,
actual_options
)
end
merge_commit_sha
end
def
revert_merge
(
user
,
merge_commit_id
,
revert_branch_name
)
find_or_create_branch
(
user
,
revert_branch_name
,
merge_commit_id
)
new_index
=
rugged
.
revert_commit
(
merge_commit_id
,
merge_commit_id
,
mainline:
1
)
committer
=
user_to_committer
(
user
)
commit_with_hooks
(
user
,
revert_branch_name
)
do
|
ref
|
options
=
{
message:
'Revert MR'
,
author:
committer
,
committer:
committer
,
tree:
new_index
.
write_tree
(
rugged
),
parents:
[
rugged
.
lookup
(
merge_commit_id
)],
update_ref:
ref
}
Rugged
::
Commit
.
create
(
rugged
,
options
)
end
end
def
merged_to_root_ref?
(
branch_name
)
...
...
app/services/merge_requests/merge_service.rb
View file @
f56ee9d3
...
...
@@ -34,7 +34,8 @@ module MergeRequests
committer:
committer
}
repository
.
merge
(
current_user
,
merge_request
.
source_sha
,
merge_request
.
target_branch
,
options
)
commit_id
=
repository
.
merge
(
current_user
,
merge_request
.
source_sha
,
merge_request
.
target_branch
,
options
)
merge_request
.
update
(
merge_commit_sha:
commit_id
)
rescue
StandardError
=>
e
merge_request
.
update
(
merge_error:
"Something went wrong during merge"
)
Rails
.
logger
.
error
(
e
.
message
)
...
...
db/migrate/20160129155512_add_merge_commit_sha_to_merge_requests.rb
0 → 100644
View file @
f56ee9d3
class
AddMergeCommitShaToMergeRequests
<
ActiveRecord
::
Migration
def
change
add_column
:merge_requests
,
:merge_commit_sha
,
:string
end
end
spec/factories/merge_requests.rb
View file @
f56ee9d3
...
...
@@ -24,6 +24,7 @@
# merge_params :text
# merge_when_build_succeeds :boolean default(FALSE), not null
# merge_user_id :integer
# merge_commit_sha :string
#
FactoryGirl
.
define
do
...
...
spec/models/merge_request_spec.rb
View file @
f56ee9d3
...
...
@@ -24,6 +24,7 @@
# merge_params :text
# merge_when_build_succeeds :boolean default(FALSE), not null
# merge_user_id :integer
# merge_commit_sha :string
#
require
'spec_helper'
...
...
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