Skip to content

Commit

Permalink
0001349 recognize remote branches for Version.h in detached head state
Browse files Browse the repository at this point in the history
  • Loading branch information
5263 authored and wwmayer committed Jan 11, 2014
1 parent 70e6d38 commit a7b16c5
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/Tools/SubWCRev.py
Expand Up @@ -144,19 +144,40 @@ def extractInfo(self, srcdir):
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):
Expand Down

0 comments on commit a7b16c5

Please sign in to comment.