gitlab-org--gitlab-foss/lib/gitlab/git.rb

72 lines
1.5 KiB
Ruby
Raw Normal View History

module Gitlab
module Git
BLANK_SHA = ('0' * 40).freeze
2015-11-02 13:02:08 -05:00
TAG_REF_PREFIX = "refs/tags/".freeze
BRANCH_REF_PREFIX = "refs/heads/".freeze
CommandError = Class.new(StandardError)
CommitError = Class.new(StandardError)
class << self
2017-06-28 08:20:29 -04:00
include Gitlab::EncodingHelper
def ref_name(ref)
encode_utf8(ref).sub(/\Arefs\/(tags|heads|remotes)\//, '')
end
def branch_name(ref)
ref = ref.to_s
if self.branch_ref?(ref)
self.ref_name(ref)
else
nil
end
end
def committer_hash(email:, name:)
2016-09-20 12:07:52 -04:00
return if email.nil? || name.nil?
{
email: email,
name: name,
time: Time.now
}
end
def tag_name(ref)
ref = ref.to_s
if self.tag_ref?(ref)
self.ref_name(ref)
else
nil
end
end
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
2015-12-14 20:30:55 -05:00
def version
Gitlab::VersionInfo.parse(Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --version)).first)
end
def check_namespace!(*objects)
expected_namespace = self.name + '::'
objects.each do |object|
unless object.class.name.start_with?(expected_namespace)
raise ArgumentError, "expected object in #{expected_namespace}, got #{object}"
end
end
end
end
end
end