BigW Consortium Gitlab

force_push.rb 713 Bytes
Newer Older
1 2 3
module Gitlab
  module Checks
    class ForcePush
4
      def self.force_push?(project, oldrev, newrev)
5 6 7
        return false if project.empty_repo?

        # Created or deleted branch
8 9 10 11 12 13 14
        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
15
              .ancestor?(oldrev, newrev)
16 17 18 19 20
          else
            Gitlab::Git::RevList.new(
              path_to_repo: project.repository.path_to_repo,
              oldrev: oldrev, newrev: newrev).missed_ref.present?
          end
21 22 23 24 25
        end
      end
    end
  end
end