2016-02-03 18:28:40 -05:00
|
|
|
module Commits
|
2016-04-18 03:39:07 -04:00
|
|
|
class RevertService < ChangeService
|
2016-02-03 18:28:40 -05:00
|
|
|
def commit
|
2016-02-15 16:13:41 -05:00
|
|
|
revert_into = @create_merge_request ? @commit.revert_branch_name : @target_branch
|
2016-02-24 12:00:34 -05:00
|
|
|
revert_tree_id = repository.check_revert_content(@commit, @target_branch)
|
2016-02-15 16:13:41 -05:00
|
|
|
|
2016-02-24 12:00:34 -05:00
|
|
|
if revert_tree_id
|
|
|
|
create_target_branch(revert_into) if @create_merge_request
|
2016-02-10 16:05:04 -05:00
|
|
|
|
2016-02-24 12:00:34 -05:00
|
|
|
repository.revert(current_user, @commit, revert_into, revert_tree_id)
|
|
|
|
success
|
|
|
|
else
|
2016-04-18 03:39:07 -04:00
|
|
|
error_msg = "Sorry, we cannot revert this #{@commit.change_type_title} automatically.
|
2016-02-15 16:13:41 -05:00
|
|
|
It may have already been reverted, or a more recent commit may have updated some of its content."
|
2016-04-18 03:39:07 -04:00
|
|
|
raise ChangeError, error_msg
|
2016-02-10 16:05:04 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-03 18:28:40 -05:00
|
|
|
end
|
|
|
|
end
|