BigW Consortium Gitlab

git.rb 1.09 KB
Newer Older
1 2
module Gitlab
  module Git
3
    BLANK_SHA = ('0' * 40).freeze
4 5
    TAG_REF_PREFIX = "refs/tags/".freeze
    BRANCH_REF_PREFIX = "refs/heads/".freeze
6

7 8 9 10 11
    class << self
      def ref_name(ref)
        ref.gsub(/\Arefs\/(tags|heads)\//, '')
      end

12 13 14 15 16 17 18 19 20
      def branch_name(ref)
        ref = ref.to_s
        if self.branch_ref?(ref)
          self.ref_name(ref)
        else
          nil
        end
      end

21
      def committer_hash(email:, name:)
22 23
        return if email.nil? || name.nil?

24 25 26 27 28 29 30
        {
          email: email,
          name: name,
          time: Time.now
        }
      end

31 32 33 34 35 36 37 38 39
      def tag_name(ref)
        ref = ref.to_s
        if self.tag_ref?(ref)
          self.ref_name(ref)
        else
          nil
        end
      end

40 41 42 43 44 45 46 47 48 49 50
      def tag_ref?(ref)
        ref.start_with?(TAG_REF_PREFIX)
      end

      def branch_ref?(ref)
        ref.start_with?(BRANCH_REF_PREFIX)
      end

      def blank_ref?(ref)
        ref == BLANK_SHA
      end
51 52 53 54

      def version
        Gitlab::VersionInfo.parse(Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --version)).first)
      end
55
    end
56 57
  end
end