BigW Consortium Gitlab

rev_list.rb 1.02 KB
Newer Older
1 2 3
module Gitlab
  module Git
    class RevList
4 5
      attr_reader :project, :env

6
      ALLOWED_VARIABLES = %w[GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES].freeze
7

8
      def initialize(oldrev, newrev, project:, env: nil)
9 10
        @project = project
        @env = env.presence || {}
11 12 13 14 15 16 17 18 19
        @args = [Gitlab.config.git.bin_path,
                 "--git-dir=#{project.repository.path_to_repo}",
                 "rev-list",
                 "--max-count=1",
                 oldrev,
                 "^#{newrev}"]
      end

      def execute
20 21 22 23
        Gitlab::Popen.popen(@args, nil, parse_environment_variables)
      end

      def valid?
24
        environment_variables.all? do |(name, value)|
25
          value.to_s.start_with?(project.repository.path_to_repo)
26
        end
27 28 29 30
      end

      private

31 32 33
      def parse_environment_variables
        return {} unless valid?

34 35 36 37
        environment_variables
      end

      def environment_variables
38
        @environment_variables ||= env.slice(*ALLOWED_VARIABLES).compact
39 40 41 42
      end
    end
  end
end