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
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
Show 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
flash
[
:notice
]
=
success_notice
||
"Your changes have been successfully committed."
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"
flash
[
:notice
]
<<
" You can now submit a merge request to get this change into the original
#{
target
}
."
end
...
...
@@ -62,6 +62,17 @@ module CreatesCommit
)
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?
@mr_source_project
!=
@mr_target_project
end
...
...
@@ -75,7 +86,7 @@ module CreatesCommit
end
def
set_commit_variables
@mr_source_branch
=
@target_branch
@mr_source_branch
||
=
@target_branch
if
can?
(
current_user
,
:push_code
,
@project
)
# Edit file in this project
...
...
@@ -89,7 +100,7 @@ module CreatesCommit
else
# Merge request to this project
@mr_target_project
=
@project
@mr_target_branch
=
@ref
@mr_target_branch
||
=
@ref
end
else
# Edit file in fork
...
...
app/controllers/projects/commit_controller.rb
View file @
b36319a1
...
...
@@ -93,10 +93,13 @@ class Projects::CommitController < Projects::ApplicationController
end
def
assign_revert_commit_vars
@commit
=
project
.
commit
(
params
[
:id
])
@target_branch
=
params
[
:target_branch
]
@mr_source_branch
=
@commit
.
revert_branch_name
@mr_target_branch
=
@target_branch
@commit_params
=
{
revert_commit_id:
params
[
:id
],
commit:
@commit
,
create_merge_request:
params
[
:create_merge_request
].
present?
||
different_project?
}
end
end
app/models/repository.rb
View file @
b36319a1
...
...
@@ -622,22 +622,24 @@ class Repository
merge_commit_sha
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
target_sha
=
find_branch
(
target_branch
).
try
(
:target
)
# First make revert in temp branch
unless
target_sha
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
end
status
=
target_sha
?
true
:
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
# Make the revert happen in the target branch
source_sha
=
find_branch
(
target_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
)
revert_commit
(
user
,
commit_id
,
base_branch
,
base_branch
,
commit_message
)
if
has_changes
&&
!
create_mr
status
=
revert_commit
(
user
,
commit_id
,
base_branch
,
base_branch
,
commit_message
)
end
::
File
.
open
(
'/Users/ruben/Desktop/log.txt'
,
'w'
)
{
|
f
|
f
.
puts
"HAS CHANGES:
#{
has_changes
&&
status
}
"
}
has_changes
&&
status
end
def
revert_commit
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
)
...
...
app/services/commits/revert_service.rb
View file @
b36319a1
...
...
@@ -5,7 +5,8 @@ module Commits
def
execute
@source_project
=
params
[
:source_project
]
||
@project
@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
validate
...
...
@@ -23,10 +24,13 @@ module Commits
raw_repo
=
repository
.
rugged
# Create branch with revert commit
reverted
=
repository
.
revert
(
current_user
,
@commit_to_revert
.
id
,
@commit_to_revert
.
revert_branch_name
,
@target_branch
,
@commit_to_revert
.
revert_message
)
repository
.
rm_branch
(
current_user
,
@commit_to_revert
.
revert_branch_name
)
reverted
=
repository
.
revert
(
current_user
,
@commit
.
id
,
@commit
.
revert_branch_name
,
@target_branch
,
@commit
.
revert_message
,
@create_merge_request
)
unless
@create_merge_request
repository
.
rm_branch
(
current_user
,
@commit
.
revert_branch_name
)
end
reverted
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