2015-04-26 12:48:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module Git
|
2016-04-02 18:10:28 +05:30
|
|
|
BLANK_SHA = ('0' * 40).freeze
|
|
|
|
TAG_REF_PREFIX = "refs/tags/".freeze
|
|
|
|
BRANCH_REF_PREFIX = "refs/heads/".freeze
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
class << self
|
|
|
|
def ref_name(ref)
|
|
|
|
ref.gsub(/\Arefs\/(tags|heads)\//, '')
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def branch_name(ref)
|
|
|
|
ref = ref.to_s
|
|
|
|
if self.branch_ref?(ref)
|
|
|
|
self.ref_name(ref)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def committer_hash(email:, name:)
|
|
|
|
return if email.nil? || name.nil?
|
|
|
|
|
|
|
|
{
|
|
|
|
email: email,
|
|
|
|
name: name,
|
|
|
|
time: Time.now
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def tag_name(ref)
|
|
|
|
ref = ref.to_s
|
|
|
|
if self.tag_ref?(ref)
|
|
|
|
self.ref_name(ref)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
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
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
def version
|
|
|
|
Gitlab::VersionInfo.parse(Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} --version)).first)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|