2014-11-03 14:02:12 -05:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
2015-11-03 07:09:18 -05:00
|
|
|
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
|
2015-01-15 13:26:33 -05:00
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
CommandError = Class.new(StandardError)
|
2017-09-01 06:11:59 -04:00
|
|
|
CommitError = Class.new(StandardError)
|
2017-02-15 21:08:30 -05:00
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
class << self
|
2017-06-28 08:20:29 -04:00
|
|
|
include Gitlab::EncodingHelper
|
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
def ref_name(ref)
|
2017-09-12 10:07:31 -04:00
|
|
|
encode_utf8(ref).sub(/\Arefs\/(tags|heads|remotes)\//, '')
|
2015-03-10 06:51:36 -04:00
|
|
|
end
|
|
|
|
|
2016-07-28 00:04:57 -04:00
|
|
|
def branch_name(ref)
|
|
|
|
ref = ref.to_s
|
|
|
|
if self.branch_ref?(ref)
|
|
|
|
self.ref_name(ref)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-08 11:40:07 -04:00
|
|
|
def committer_hash(email:, name:)
|
2016-09-20 12:07:52 -04:00
|
|
|
return if email.nil? || name.nil?
|
|
|
|
|
2016-09-08 11:40:07 -04:00
|
|
|
{
|
|
|
|
email: email,
|
|
|
|
name: name,
|
|
|
|
time: Time.now
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-07-28 00:04:57 -04:00
|
|
|
def tag_name(ref)
|
|
|
|
ref = ref.to_s
|
|
|
|
if self.tag_ref?(ref)
|
|
|
|
self.ref_name(ref)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
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
|
2017-09-19 13:09:10 -04:00
|
|
|
|
|
|
|
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
|
2017-10-10 13:44:14 -04:00
|
|
|
|
|
|
|
def diff_line_code(file_path, new_line_position, old_line_position)
|
|
|
|
"#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}"
|
|
|
|
end
|
2015-01-15 13:26:33 -05:00
|
|
|
end
|
2014-11-03 14:02:12 -05:00
|
|
|
end
|
|
|
|
end
|