summaryrefslogtreecommitdiff
path: root/lib/gitlab/checks/force_push.rb
blob: dc5d285ea65bf79a2c787c7f9a4cadc84cd4213a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Gitlab
  module Checks
    class ForcePush
      def self.force_push?(project, oldrev, newrev)
        return false if project.empty_repo?

        # Created or deleted branch
        return false if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)

        GitalyClient.migrate(:force_push) do |is_enabled|
          if is_enabled
            !project
              .repository
              .gitaly_commit_client
              .ancestor?(oldrev, newrev)
          else
            Gitlab::Git::RevList.new(
              path_to_repo: project.repository.path_to_repo,
              oldrev: oldrev, newrev: newrev).missed_ref.present?
          end
        end
      end
    end
  end
end