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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
df5f362c
Commit
df5f362c
authored
Feb 01, 2016
by
Rubén Dávila
Committed by
Robert Speicher
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some specs plus some refactor.
parent
b5935f07
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
10 deletions
+43
-10
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+4
-2
app/models/merge_request.rb
app/models/merge_request.rb
+8
-0
app/models/repository.rb
app/models/repository.rb
+5
-8
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+26
-0
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
df5f362c
...
...
@@ -199,11 +199,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
target_branch:
@merge_request
.
target_branch
,
source_project_id:
@merge_request
.
target_project_id
,
target_project_id:
@merge_request
.
target_project_id
,
description:
"Reverts
#{
@merge_request
.
to_reference
}
"
description:
@merge_request
.
revert_description
}}
if
target_branch_exists
@repository
.
revert_merge
(
current_user
,
@merge_request
)
@repository
.
revert_merge
(
current_user
,
@merge_request
.
merge_commit_sha
,
@merge_request
.
revert_branch_name
,
@merge_request
.
revert_title
)
redirect_to
new_namespace_project_merge_request_url
(
@project
.
namespace
,
@project
,
url_params
)
else
redirect_to
namespace_project_merge_request_url
(
@project
.
namespace
,
@project
,
@merge_request
),
...
...
app/models/merge_request.rb
View file @
df5f362c
...
...
@@ -537,4 +537,12 @@ class MergeRequest < ActiveRecord::Base
def
revert_branch_name
"revert-
#{
iid
}
-
#{
target_branch
}
"
end
def
revert_title
"Revert
\"
#{
title
}
\"
"
end
def
revert_description
"Reverts
#{
to_reference
}
"
end
end
app/models/repository.rb
View file @
df5f362c
...
...
@@ -622,25 +622,22 @@ class Repository
merge_commit_sha
end
def
revert_merge
(
user
,
merge_request
)
revert_branch_name
=
merge_request
.
revert_branch_name
merge_commit_id
=
merge_request
.
merge_commit_sha
def
revert_merge
(
user
,
merge_commit_id
,
new_branch_name
,
commit_message
)
# branch exists and it's highly probable that it has the revert commit
return
if
find_branch
(
revert
_branch_name
)
return
if
find_branch
(
new
_branch_name
)
add_branch
(
user
,
revert
_branch_name
,
merge_commit_id
)
add_branch
(
user
,
new
_branch_name
,
merge_commit_id
)
new_index
=
rugged
.
revert_commit
(
merge_commit_id
,
merge_commit_id
,
mainline:
1
)
committer
=
user_to_committer
(
user
)
options
=
{
message:
"Revert
\"
#{
merge_request
.
title
}
\"
"
,
message:
commit_message
,
author:
committer
,
committer:
committer
,
tree:
new_index
.
write_tree
(
rugged
),
parents:
[
rugged
.
lookup
(
merge_commit_id
)],
update_ref:
"refs/heads/
#{
revert
_branch_name
}
"
update_ref:
"refs/heads/
#{
new
_branch_name
}
"
}
Rugged
::
Commit
.
create
(
rugged
,
options
)
...
...
spec/models/repository_spec.rb
View file @
df5f362c
...
...
@@ -5,6 +5,15 @@ describe Repository, models: true do
let
(
:repository
)
{
create
(
:project
).
repository
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:commit_options
)
do
author
=
repository
.
user_to_committer
(
user
)
{
message:
'Test message'
,
committer:
author
,
author:
author
}
end
let
(
:merge_commit_id
)
do
master_commit
=
repository
.
commit
(
'master'
)
source_sha
=
repository
.
find_branch
(
'feature'
).
target
repository
.
merge
(
user
,
source_sha
,
'master'
,
commit_options
)
end
describe
:branch_names_contains
do
subject
{
repository
.
branch_names_contains
(
sample_commit
.
id
)
}
...
...
@@ -426,4 +435,21 @@ describe Repository, models: true do
it
{
is_expected
.
not_to
include
(
'e56497bb5f03a90a51293fc6d516788730953899'
)
}
end
describe
'#merge'
do
it
'should merge the code and return the commit id'
do
expect
(
merge_commit_id
).
to
be_present
expect
(
repository
.
blob_at
(
merge_commit_id
,
'files/ruby/feature.rb'
)).
to
be_present
end
end
describe
'#revert_merge'
do
it
'should revert the changes'
do
repository
.
revert_merge
(
user
,
merge_commit_id
,
'revert-changes'
,
'Revert changes'
)
source_sha
=
repository
.
find_branch
(
'revert-changes'
).
target
repository
.
merge
(
user
,
source_sha
,
'master'
,
commit_options
)
expect
(
repository
.
blob_at_branch
(
'master'
,
'files/ruby/feature.rb'
)).
not_to
be_present
end
end
end
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