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
Jérome Perrin
gitlab-ce
Commits
b36319a1
Commit
b36319a1
authored
Feb 05, 2016
by
Rubén Dávila
Committed by
Robert Speicher
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make MRs with revert commit work.
parent
80613993
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
17 deletions
+37
-17
app/controllers/concerns/creates_commit.rb
app/controllers/concerns/creates_commit.rb
+14
-3
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+5
-2
app/models/repository.rb
app/models/repository.rb
+8
-6
app/services/commits/revert_service.rb
app/services/commits/revert_service.rb
+10
-6
No files found.
app/controllers/concerns/creates_commit.rb
View file @
b36319a1
...
@@ -16,7 +16,7 @@ module CreatesCommit
...
@@ -16,7 +16,7 @@ module CreatesCommit
flash
[
:notice
]
=
success_notice
||
"Your changes have been successfully committed."
flash
[
:notice
]
=
success_notice
||
"Your changes have been successfully committed."
if
create_merge_request?
if
create_merge_request?
success_path
=
new_merge_request_path
success_path
=
merge_request_exists?
?
existent_merge_request_path
:
new_merge_request_path
target
=
different_project?
?
"project"
:
"branch"
target
=
different_project?
?
"project"
:
"branch"
flash
[
:notice
]
<<
" You can now submit a merge request to get this change into the original
#{
target
}
."
flash
[
:notice
]
<<
" You can now submit a merge request to get this change into the original
#{
target
}
."
end
end
...
@@ -62,6 +62,17 @@ module CreatesCommit
...
@@ -62,6 +62,17 @@ module CreatesCommit
)
)
end
end
def
existent_merge_request_path
namespace_project_merge_request_path
(
@mr_target_project
.
namespace
,
@mr_target_project
,
@merge_request
)
end
def
merge_request_exists?
@merge_request
=
@mr_target_project
.
merge_requests
.
opened
.
where
(
source_branch:
@mr_source_branch
,
target_branch:
@mr_target_branch
).
first
end
def
different_project?
def
different_project?
@mr_source_project
!=
@mr_target_project
@mr_source_project
!=
@mr_target_project
end
end
...
@@ -75,7 +86,7 @@ module CreatesCommit
...
@@ -75,7 +86,7 @@ module CreatesCommit
end
end
def
set_commit_variables
def
set_commit_variables
@mr_source_branch
=
@target_branch
@mr_source_branch
||
=
@target_branch
if
can?
(
current_user
,
:push_code
,
@project
)
if
can?
(
current_user
,
:push_code
,
@project
)
# Edit file in this project
# Edit file in this project
...
@@ -89,7 +100,7 @@ module CreatesCommit
...
@@ -89,7 +100,7 @@ module CreatesCommit
else
else
# Merge request to this project
# Merge request to this project
@mr_target_project
=
@project
@mr_target_project
=
@project
@mr_target_branch
=
@ref
@mr_target_branch
||
=
@ref
end
end
else
else
# Edit file in fork
# Edit file in fork
...
...
app/controllers/projects/commit_controller.rb
View file @
b36319a1
...
@@ -93,10 +93,13 @@ class Projects::CommitController < Projects::ApplicationController
...
@@ -93,10 +93,13 @@ class Projects::CommitController < Projects::ApplicationController
end
end
def
assign_revert_commit_vars
def
assign_revert_commit_vars
@commit
=
project
.
commit
(
params
[
:id
])
@target_branch
=
params
[
:target_branch
]
@target_branch
=
params
[
:target_branch
]
@mr_source_branch
=
@commit
.
revert_branch_name
@mr_target_branch
=
@target_branch
@commit_params
=
{
@commit_params
=
{
revert_commit_id:
params
[
:id
],
commit:
@commit
,
create_merge_request:
params
[
:create_merge_request
].
present?
||
different_project?
}
}
end
end
end
end
app/models/repository.rb
View file @
b36319a1
...
@@ -622,22 +622,24 @@ class Repository
...
@@ -622,22 +622,24 @@ class Repository
merge_commit_sha
merge_commit_sha
end
end
def
revert
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
def
revert
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
,
create_mr
=
false
)
source_sha
=
find_branch
(
base_branch
).
target
source_sha
=
find_branch
(
base_branch
).
target
target_sha
=
find_branch
(
target_branch
).
try
(
:target
)
target_sha
=
find_branch
(
target_branch
).
try
(
:target
)
# First make revert in temp branch
# First make revert in temp branch
unless
target_sha
status
=
target_sha
?
true
:
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
end
# Make the revert happen in the target branch
# Make the revert happen in the target branch
source_sha
=
find_branch
(
target_branch
).
target
source_sha
=
find_branch
(
target_branch
).
target
target_sha
=
find_branch
(
base_branch
).
target
target_sha
=
find_branch
(
base_branch
).
target
has_changes
=
is_there_something_to_merge?
(
source_sha
,
target_sha
)
if
is_there_something_to_merge?
(
source_sha
,
target_sha
)
if
has_changes
&&
!
create_mr
revert_commit
(
user
,
commit_id
,
base_branch
,
base_branch
,
commit_message
)
status
=
revert_commit
(
user
,
commit_id
,
base_branch
,
base_branch
,
commit_message
)
end
end
::
File
.
open
(
'/Users/ruben/Desktop/log.txt'
,
'w'
)
{
|
f
|
f
.
puts
"HAS CHANGES:
#{
has_changes
&&
status
}
"
}
has_changes
&&
status
end
end
def
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
def
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
...
...
app/services/commits/revert_service.rb
View file @
b36319a1
...
@@ -4,8 +4,9 @@ module Commits
...
@@ -4,8 +4,9 @@ module Commits
def
execute
def
execute
@source_project
=
params
[
:source_project
]
||
@project
@source_project
=
params
[
:source_project
]
||
@project
@target_branch
=
params
[
:target_branch
]
@target_branch
=
params
[
:target_branch
]
@commit_to_revert
=
@source_project
.
commit
(
params
[
:revert_commit_id
])
@commit
=
params
[
:commit
]
@create_merge_request
=
params
[
:create_merge_request
]
# Check push permissions to branch
# Check push permissions to branch
validate
validate
...
@@ -23,10 +24,13 @@ module Commits
...
@@ -23,10 +24,13 @@ module Commits
raw_repo
=
repository
.
rugged
raw_repo
=
repository
.
rugged
# Create branch with revert commit
# Create branch with revert commit
reverted
=
repository
.
revert
(
current_user
,
@commit_to_revert
.
id
,
reverted
=
repository
.
revert
(
current_user
,
@commit
.
id
,
@commit_to_revert
.
revert_branch_name
,
@target_branch
,
@commit
.
revert_branch_name
,
@target_branch
,
@commit_to_revert
.
revert_message
)
@commit
.
revert_message
,
@create_merge_request
)
repository
.
rm_branch
(
current_user
,
@commit_to_revert
.
revert_branch_name
)
unless
@create_merge_request
repository
.
rm_branch
(
current_user
,
@commit
.
revert_branch_name
)
end
reverted
reverted
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