Reload mr code on force push too
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
9211b541d3
commit
835cbc06d8
3 changed files with 22 additions and 9 deletions
|
@ -3,6 +3,7 @@ module MergeRequests
|
|||
def execute(oldrev, newrev, ref)
|
||||
return true unless ref =~ /heads/
|
||||
|
||||
@oldrev, @newrev = oldrev, newrev
|
||||
@branch_name = ref.gsub("refs/heads/", "")
|
||||
@fork_merge_requests = @project.fork_merge_requests.opened
|
||||
@commits = @project.repository.commits_between(oldrev, newrev)
|
||||
|
@ -35,6 +36,10 @@ module MergeRequests
|
|||
end
|
||||
end
|
||||
|
||||
def force_push?
|
||||
Gitlab::ForcePushCheck.force_push?(@project, @oldrev, @newrev)
|
||||
end
|
||||
|
||||
# Refresh merge request diff if we push to source or target branch of merge request
|
||||
# Note: we should update merge requests from forks too
|
||||
def reload_merge_requests
|
||||
|
@ -44,7 +49,7 @@ module MergeRequests
|
|||
|
||||
merge_requests.each do |merge_request|
|
||||
|
||||
if merge_request.source_branch == @branch_name
|
||||
if merge_request.source_branch == @branch_name || force_push?
|
||||
merge_request.reload_code
|
||||
merge_request.mark_as_unchecked
|
||||
else
|
||||
|
|
15
lib/gitlab/force_push_check.rb
Normal file
15
lib/gitlab/force_push_check.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Gitlab
|
||||
class ForcePushCheck
|
||||
def self.force_push?(project, oldrev, newrev)
|
||||
return false if project.empty_repo?
|
||||
|
||||
if oldrev != Gitlab::Git::BLANK_SHA && newrev != Gitlab::Git::BLANK_SHA
|
||||
missed_refs = IO.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev})).read
|
||||
missed_refs.split("\n").size > 0
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -94,14 +94,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def forced_push?(project, oldrev, newrev)
|
||||
return false if project.empty_repo?
|
||||
|
||||
if oldrev != Gitlab::Git::BLANK_SHA && newrev != Gitlab::Git::BLANK_SHA
|
||||
missed_refs = IO.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev})).read
|
||||
missed_refs.split("\n").size > 0
|
||||
else
|
||||
false
|
||||
end
|
||||
Gitlab::ForcePushCheck.force_push?(project, oldrev, newrev)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue