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
Kazuhiko Shiozaki
gitlab-ce
Commits
91e6e32d
Commit
91e6e32d
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 it work for merge commits.
parent
b36319a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
10 deletions
+15
-10
app/models/commit.rb
app/models/commit.rb
+4
-0
app/models/repository.rb
app/models/repository.rb
+10
-7
app/services/commits/revert_service.rb
app/services/commits/revert_service.rb
+1
-3
No files found.
app/models/commit.rb
View file @
91e6e32d
...
...
@@ -223,6 +223,10 @@ class Commit
"Revert
\"
#{
safe_message
.
lines
.
first
}
\"
"
.
truncate
(
80
)
+
"
\n\n
Reverts
#{
to_reference
}
"
end
def
is_a_merge_commit?
parents
.
size
>
1
end
private
def
repo_changes
...
...
app/models/repository.rb
View file @
91e6e32d
...
...
@@ -622,12 +622,13 @@ class Repository
merge_commit_sha
end
def
revert
(
user
,
commit_id
,
target_branch
,
base_branch
,
commit_message
,
create_mr
=
false
)
def
revert
(
user
,
commit
,
base_branch
,
create_mr
=
false
)
target_branch
=
commit
.
revert_branch_name
source_sha
=
find_branch
(
base_branch
).
target
target_sha
=
find_branch
(
target_branch
).
try
(
:target
)
# First make revert in temp branch
status
=
target_sha
?
true
:
revert_commit
(
user
,
commit
_id
,
target_branch
,
base_branch
,
commit_message
)
status
=
target_sha
?
true
:
revert_commit
(
user
,
commit
,
target_branch
,
base_branch
)
# Make the revert happen in the target branch
source_sha
=
find_branch
(
target_branch
).
target
...
...
@@ -635,24 +636,26 @@ class Repository
has_changes
=
is_there_something_to_merge?
(
source_sha
,
target_sha
)
if
has_changes
&&
!
create_mr
status
=
revert_commit
(
user
,
commit
_id
,
base_branch
,
base_branch
,
commit_message
)
status
=
revert_commit
(
user
,
commit
,
base_branch
,
base_branch
)
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
)
def
revert_commit
(
user
,
commit
,
target_branch
,
base_branch
)
base_sha
=
find_branch
(
base_branch
).
target
commit_with_hooks
(
user
,
target_branch
)
do
|
ref
|
new_index
=
rugged
.
revert_commit
(
commit_id
,
base_sha
)
#, mainline: 1)
args
=
[
commit
.
id
,
base_sha
]
args
<<
{
mainline:
1
}
if
commit
.
is_a_merge_commit?
new_index
=
rugged
.
revert_commit
(
*
args
)
return
false
if
new_index
.
conflicts?
committer
=
user_to_committer
(
user
)
source_sha
=
Rugged
::
Commit
.
create
(
rugged
,
{
message:
commit_message
,
message:
commit
.
revert
_message
,
author:
committer
,
committer:
committer
,
tree:
new_index
.
write_tree
(
rugged
),
...
...
app/services/commits/revert_service.rb
View file @
91e6e32d
...
...
@@ -24,9 +24,7 @@ module Commits
raw_repo
=
repository
.
rugged
# Create branch with revert commit
reverted
=
repository
.
revert
(
current_user
,
@commit
.
id
,
@commit
.
revert_branch_name
,
@target_branch
,
@commit
.
revert_message
,
@create_merge_request
)
reverted
=
repository
.
revert
(
current_user
,
@commit
,
@target_branch
,
@create_merge_request
)
unless
@create_merge_request
repository
.
rm_branch
(
current_user
,
@commit
.
revert_branch_name
)
...
...
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