def predictLiveBuildId(self):
if self.__commit:
return [ bytes.fromhex(self.__commit) ]
if self.__tag:
# Annotated tags are objects themselves. We need the commit object!
refs = ["refs/tags/" + self.__tag + '^{}', "refs/tags/" + self.__tag]
else:
refs = ["refs/heads/" + self.__branch]
cmdLine = ['git', 'ls-remote', self.__url] + refs
try:
output = subprocess.check_output(cmdLine, universal_newlines=True,
stderr=subprocess.DEVNULL).strip()
except subprocess.CalledProcessError as e:
return [None]
# have we found anything at all?
if not output:
return [None]
# See if we got one of our intended refs. Git is generating lines with
# the following format:
#
# <sha1>\t<refname>
#
# Put the output into a dict with the refname as key. Be extra careful
# and strip out lines not matching this pattern.
output = {
commitAndRef[1].strip() : bytes.fromhex(commitAndRef[0].strip())
for commitAndRef
in (line.split('\t') for line in output.split('\n'))
if len(commitAndRef) == 2 }
for ref in refs:
if ref in output: return [output[ref]]
# uhh, should not happen...
return [None]
评论列表
文章目录