From a7b16c5748bd3146673bd31a6996eb37de3e32d0 Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Fri, 10 Jan 2014 14:19:49 +0100 Subject: [PATCH] 0001349 recognize remote branches for Version.h in detached head state --- src/Tools/SubWCRev.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Tools/SubWCRev.py b/src/Tools/SubWCRev.py index b79a3e61d..2b6e91d6a 100644 --- a/src/Tools/SubWCRev.py +++ b/src/Tools/SubWCRev.py @@ -144,19 +144,40 @@ class GitControl(VersionControl): if r != None: self.date = r.groups()[0].replace('-','/') break - self.url = "Unknown" - info=os.popen("git remote -v").read() - info=info.split("\n") - for i in info: - r = re.match("origin\\W+(\\S+)",i) - if r != None: - self.url = r.groups()[0] - break self.hash=os.popen("git log -1 --pretty=format:%H").read() for self.branch in os.popen("git branch").read().split('\n'): if re.match( "\*", self.branch ) != None: break self.branch=self.branch[2:] + remote='origin' #used to determine the url + if self.branch == '(no branch)': #check for remote branches + branchlst=os.popen("git show -s --pretty=%d HEAD").read()\ + .strip(" ()\n").split(', ') + if len(branchlst) >= 2: + self.branch = branchlst[1] + if '/' in self.branch: + remote=self.branch.split('/',1)[0] + else: # guess + self.branch = '(%s)' % \ + os.popen("git describe --all --dirty").read().strip() + self.url = "Unknown" + info=os.popen("git remote -v").read() + info=info.split("\n") + for i in info: + r = re.match("%s\\W+(\\S+)"%remote,i) + if r != None: + url=r.groups()[0] + if '@' not in url:#ignore urls with usernames, as might as well include a password + self.url=url + break + #if the branch name conainted any slashes but was not a remote + #there might be not result by now. Hence we assume origin + if self.url == "Unknown": + for i in info: + r = re.match("origin\\W+(\\S+)",i) + if r != None: + self.url = r.groups()[0] + break return True def printInfo(self):