Fix for an Issue #121

This commit is contained in:
Miroslav Stampar 2012-07-26 00:02:38 +02:00
parent 4a0b55f651
commit 18b1d1efd6
2 changed files with 16 additions and 6 deletions

View File

@ -21,7 +21,7 @@ def getRevisionNumber():
_ = os.path.dirname(__file__) _ = os.path.dirname(__file__)
while True: while True:
filePath = os.path.join(_, ".git/refs/heads/master").replace('/', os.path.sep) filePath = os.path.join(_, ".git", "HEAD")
if os.path.exists(filePath): if os.path.exists(filePath):
break break
else: else:
@ -30,10 +30,17 @@ def getRevisionNumber():
break break
else: else:
_ = os.path.dirname(_) _ = os.path.dirname(_)
if filePath: while True:
with open(filePath, "r") as f: if filePath and os.path.isfile(filePath):
match = re.match(r"(?i)[0-9a-f]{32}", f.read()) with open(filePath, "r") as f:
retVal = match.group(0) if match else None content = f.read()
filePath = None
if content.startswith("ref: "):
filePath = os.path.join(_, ".git", content.replace("ref: ", "")).strip()
else:
match = re.match(r"(?i)[0-9a-f]{32}", content)
retVal = match.group(0) if match else None
break
if not retVal: if not retVal:
process = execute("git rev-parse --verify HEAD", shell=True, stdout=PIPE, stderr=PIPE) process = execute("git rev-parse --verify HEAD", shell=True, stdout=PIPE, stderr=PIPE)

View File

@ -17,6 +17,7 @@ from lib.core.common import getUnicode
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.data import paths from lib.core.data import paths
from lib.core.revision import getRevisionNumber
from lib.core.settings import GIT_REPOSITORY from lib.core.settings import GIT_REPOSITORY
from lib.core.settings import IS_WIN from lib.core.settings import IS_WIN
from lib.core.settings import REVISION from lib.core.settings import REVISION
@ -49,7 +50,9 @@ def update():
success = not process.returncode success = not process.returncode
if success: if success:
logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION)) import lib.core.settings
_ = lib.core.settings.REVISION = getRevisionNumber()
logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", _))
else: else:
logger.error("update could not be completed ('%s')" % re.sub(r"\W+", " ", stderr).strip()) logger.error("update could not be completed ('%s')" % re.sub(r"\W+", " ", stderr).strip())