2018-09-28 05:00:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class Push
|
2018-09-28 08:46:22 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2018-10-05 11:35:59 -04:00
|
|
|
attr_reader :ref, :oldrev, :newrev
|
2018-09-28 06:08:11 -04:00
|
|
|
|
2018-09-28 05:00:30 -04:00
|
|
|
def initialize(project, oldrev, newrev, ref)
|
2018-09-28 06:08:11 -04:00
|
|
|
@project = project
|
2018-10-02 07:01:55 -04:00
|
|
|
@oldrev = oldrev.presence || Gitlab::Git::BLANK_SHA
|
|
|
|
@newrev = newrev.presence || Gitlab::Git::BLANK_SHA
|
2018-09-28 06:08:11 -04:00
|
|
|
@ref = ref
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_name
|
2018-09-28 08:46:22 -04:00
|
|
|
strong_memoize(:branch_name) do
|
|
|
|
Gitlab::Git.branch_name(@ref)
|
|
|
|
end
|
2018-09-28 05:00:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def branch_added?
|
|
|
|
Gitlab::Git.blank_ref?(@oldrev)
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_removed?
|
|
|
|
Gitlab::Git.blank_ref?(@newrev)
|
|
|
|
end
|
|
|
|
|
2018-09-28 09:13:04 -04:00
|
|
|
def branch_updated?
|
|
|
|
branch_push? && !branch_added? && !branch_removed?
|
|
|
|
end
|
|
|
|
|
2018-09-28 05:00:30 -04:00
|
|
|
def force_push?
|
2021-02-12 04:08:48 -05:00
|
|
|
strong_memoize(:force_push) do
|
|
|
|
Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev)
|
|
|
|
end
|
2018-09-28 05:00:30 -04:00
|
|
|
end
|
2018-09-28 06:08:11 -04:00
|
|
|
|
|
|
|
def branch_push?
|
2018-09-28 08:46:22 -04:00
|
|
|
strong_memoize(:branch_push) do
|
|
|
|
Gitlab::Git.branch_ref?(@ref)
|
|
|
|
end
|
2018-09-28 06:08:11 -04:00
|
|
|
end
|
2018-09-28 09:13:04 -04:00
|
|
|
|
|
|
|
def modified_paths
|
|
|
|
unless branch_updated?
|
|
|
|
raise ArgumentError, 'Unable to calculate modified paths!'
|
|
|
|
end
|
|
|
|
|
|
|
|
strong_memoize(:modified_paths) do
|
|
|
|
@project.repository.diff_stats(@oldrev, @newrev).paths
|
|
|
|
end
|
|
|
|
end
|
2018-09-28 05:00:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|