@@ -425,7 +425,7 @@ def add(dest):
425
425
def remove (dest ):
426
426
info ("Removing reference \" %s\" " % dest )
427
427
try :
428
- popen ([hg_cmd , 'rm' , '-f' , dest ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
428
+ pquery ([hg_cmd , 'rm' , '-f' , dest ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
429
429
except ProcessException :
430
430
pass
431
431
@@ -533,13 +533,13 @@ def getrev():
533
533
def getbranch ():
534
534
return pquery ([hg_cmd , 'branch' ]).strip () or ""
535
535
536
- def gettags (rev = None ):
536
+ def gettags ():
537
537
tags = []
538
538
refs = pquery ([hg_cmd , 'tags' ]).strip ().splitlines () or []
539
539
for ref in refs :
540
540
m = re .match (r'^(.+?)\s+(\d+)\:([a-f0-9]+)$' , ref )
541
- if m and ( not rev or m . group ( 1 ). startswith ( rev )) :
542
- tags .append (m . group ( 1 ) if rev else [m .group (3 ), m .group (1 )])
541
+ if m :
542
+ tags .append ([m .group (3 ), m .group (1 )])
543
543
return tags
544
544
545
545
def remoteid (url , rev = None ):
@@ -646,7 +646,7 @@ def add(dest):
646
646
def remove (dest ):
647
647
info ("Removing reference " + dest )
648
648
try :
649
- popen ([git_cmd , 'rm' , '-f' , dest ] + ([] if very_verbose else ['-q' ]))
649
+ pquery ([git_cmd , 'rm' , '-f' , dest ] + ([] if very_verbose else ['-q' ]))
650
650
except ProcessException :
651
651
pass
652
652
@@ -745,13 +745,18 @@ def outgoing():
745
745
if not branch :
746
746
# Default to "master" in detached mode
747
747
branch = "master"
748
+ # Check if local branch exists. If not, then just carry on
749
+ try :
750
+ pquery ([git_cmd , 'rev-parse' , '%s' % branch ])
751
+ except ProcessException :
752
+ return 0
753
+ # Check if remote branch exists. If not, then it's a new branch
748
754
try :
749
- # Check if remote branch exists
750
755
if not pquery ([git_cmd , 'rev-parse' , '%s/%s' % (remote , branch )]):
751
756
return 1
752
757
except ProcessException :
753
758
return 1
754
- # Check for outgoing commits for the same remote branch
759
+ # Check for outgoing commits for the same remote branch only if it exists locally and remotely
755
760
return 1 if pquery ([git_cmd , 'log' , '%s/%s..%s' % (remote , branch , branch )]) else 0
756
761
757
762
# Checks whether current working tree is detached
@@ -822,19 +827,19 @@ def getbranches(rev=None, ret_rev=False):
822
827
return result
823
828
824
829
# Finds tags. Will match rev if specified
825
- def gettags (rev = None ):
830
+ def gettags ():
826
831
tags = []
827
832
refs = Git .getrefs ()
828
833
for ref in refs :
829
834
m = re .match (r'^(.+)\s+refs\/tags\/(.+)$' , ref )
830
- if m and ( not rev or m . group ( 1 ). startswith ( rev )) :
835
+ if m :
831
836
t = m .group (2 )
832
837
if re .match (r'^(.+)\^\{\}$' , t ): # detect tag "pointer"
833
838
t = re .sub (r'\^\{\}$' , '' , t ) # remove "pointer" chars, e.g. some-tag^{}
834
839
for tag in tags :
835
840
if tag [1 ] == t :
836
841
tags .remove (tag )
837
- tags .append (t if rev else [m .group (1 ), t ])
842
+ tags .append ([m .group (1 ), t ])
838
843
return tags
839
844
840
845
# Finds branches a rev belongs to
@@ -1025,14 +1030,16 @@ def pathtype(cls, path=None):
1025
1030
1026
1031
return "directory" if depth == 0 else ("program" if depth == 1 else "library" )
1027
1032
1028
- @classmethod
1029
- def revtype (cls , rev , ret_rev = False ):
1033
+ def revtype (self , rev = None , ret_type = True , ret_rev = True , fmt = 3 ):
1030
1034
if rev is None or len (rev ) == 0 :
1031
- return 'latest' + (' revision in the current branch' if ret_rev else '' )
1035
+ output = ( 'latest' if fmt & 1 else '' ) + (' revision in the current branch' if fmt & 2 else '' )
1032
1036
elif re .match (r'^([a-fA-F0-9]{6,40})$' , rev ) or re .match (r'^([0-9]+)$' , rev ):
1033
- return 'rev' + (' #' + rev [0 :12 ] if ret_rev else '' )
1037
+ revtags = self .gettags (rev ) if rev else []
1038
+ output = ('rev ' if fmt & 1 else '' ) + (('#' + rev [:12 ] + ((' (tag' + ('s' if len (revtags ) > 1 else '' ) + ': ' + ', ' .join (revtags [0 :2 ]) + ')' ) if len (revtags ) else '' )) if fmt & 2 and rev else '' )
1034
1039
else :
1035
- return 'branch' + (' ' + rev if ret_rev else '' )
1040
+ output = ('branch/tag' if fmt & 1 else '' ) + (' "' + rev + '"' if fmt & 2 else '' )
1041
+
1042
+ return re .sub (r' \(' , ', ' , re .sub (r'\)' , '' , output )) if fmt & 4 else output
1036
1043
1037
1044
@classmethod
1038
1045
def isurl (cls , url ):
@@ -1085,6 +1092,13 @@ def getscm(self):
1085
1092
if os .path .isdir (os .path .join (self .path , '.' + name )):
1086
1093
return scm
1087
1094
1095
+ def gettags (self , rev = None ):
1096
+ tags = self .scm .gettags () if self .scm else []
1097
+ if rev :
1098
+ return [tag [1 ] for tag in tags if tag [0 ].startswith (rev )]
1099
+ else :
1100
+ return tags
1101
+
1088
1102
# Pass backend SCM commands and parameters if SCM exists
1089
1103
def __wrap_scm (self , method ):
1090
1104
def __scm_call (* args , ** kwargs ):
@@ -1839,17 +1853,17 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1839
1853
warning ("Importing from a local folder \" %s\" , not from a URL" % orig_url )
1840
1854
1841
1855
text = "Importing program" if top else "Adding library"
1842
- action ("%s \" %s\" from \" %s\" %s" % (text , relpath (cwd_root , repo .path ), formaturl (repo .url , protocol ), ' at ' + (repo .revtype (repo .rev , True ))))
1856
+ action ("%s \" %s\" from \" %s\" %s" % (text , relpath (cwd_root , repo .path ), formaturl (repo .url , protocol ), ' at ' + (repo .revtype (repo .rev ))))
1843
1857
if repo .clone (repo .url , repo .path , rev = repo .rev , depth = depth , protocol = protocol ):
1844
1858
with cd (repo .path ):
1845
1859
Program (repo .path ).set_root ()
1846
1860
try :
1847
1861
if repo .rev and repo .getrev () != repo .rev :
1848
1862
repo .checkout (repo .rev , True )
1849
1863
except ProcessException as e :
1850
- err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
1864
+ err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (repo .rev ))
1851
1865
if depth :
1852
- err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev , True )))
1866
+ err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev )))
1853
1867
if ignore :
1854
1868
warning (err )
1855
1869
else :
@@ -2047,14 +2061,14 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
2047
2061
action ("Updating %s \" %s\" to %s" % (
2048
2062
cwd_type if top else cwd_dest ,
2049
2063
os .path .basename (repo .path ) if top else relpath (cwd_root , repo .path ),
2050
- repo .revtype (rev , True )))
2064
+ repo .revtype (rev )))
2051
2065
2052
2066
try :
2053
2067
repo .update (rev , clean , clean_files , repo .is_local )
2054
2068
except ProcessException as e :
2055
- err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (rev , True ))
2069
+ err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (rev ))
2056
2070
if depth :
2057
- err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev , True )))
2071
+ err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev )))
2058
2072
if ignore :
2059
2073
warning (err )
2060
2074
else :
@@ -2191,10 +2205,8 @@ def sync(recursive=True, keep_refs=False, top=True):
2191
2205
"View the dependency tree of the current program or library." ))
2192
2206
def list_ (detailed = False , prefix = '' , p_path = None , ignore = False ):
2193
2207
repo = Repo .fromrepo ()
2194
- revtags = repo .scm .gettags (repo .rev ) if repo .rev else []
2195
- revstr = ('#' + repo .rev [:12 ] + (', tags: ' + ', ' .join (revtags [0 :2 ]) if len (revtags ) else '' )) if repo .rev else ''
2196
2208
2197
- print "%s (%s)" % (prefix + (relpath (p_path , repo .path ) if p_path else repo .name ), ((repo .url + ('#' + str (repo .rev )[:12 ] if repo .rev else '' ) if detailed else revstr ) or 'no revision' ))
2209
+ print "%s (%s)" % (prefix + (relpath (p_path , repo .path ) if p_path else repo .name ), ((repo .url + ('#' + str (repo .rev )[:12 ] if repo .rev else '' ) if detailed else repo . revtype ( repo . rev , fmt = 6 ) ) or 'no revision' ))
2198
2210
2199
2211
for i , lib in enumerate (sorted (repo .libs , key = lambda l : l .path )):
2200
2212
nprefix = (prefix [:- 3 ] + ('| ' if prefix [- 3 ] == '|' else ' ' )) if prefix else ''
@@ -2216,9 +2228,8 @@ def list_(detailed=False, prefix='', p_path=None, ignore=False):
2216
2228
"Show release tags for the current program or library." ))
2217
2229
def releases_ (detailed = False , unstable = False , recursive = False , prefix = '' , p_path = None ):
2218
2230
repo = Repo .fromrepo ()
2219
- tags = repo .scm .gettags ()
2220
- revtags = repo .scm .gettags (repo .rev ) if repo .rev else [] # associated tags with current commit
2221
- revstr = ('#' + repo .rev [:12 ] + (', tags: ' + ', ' .join (revtags [0 :2 ]) if len (revtags ) else '' )) if repo .rev else ''
2231
+ tags = repo .gettags ()
2232
+ revtags = repo .gettags (repo .rev ) if repo .rev and len (tags ) else [] # associated tags with current commit
2222
2233
regex_rels = regex_rels_all if unstable else regex_rels_official
2223
2234
2224
2235
# Generate list of tags
@@ -2228,7 +2239,7 @@ def releases_(detailed=False, unstable=False, recursive=False, prefix='', p_path
2228
2239
rels .append (tag [1 ] + " %s%s" % ('#' + tag [0 ] if detailed else "" , " <- current" if tag [1 ] in revtags else "" ))
2229
2240
2230
2241
# Print header
2231
- print "%s (%s)" % (prefix + (relpath (p_path , repo .path ) if p_path else repo .name ), ((repo .url + ('#' + str (repo .rev )[:12 ] if repo .rev else '' ) if detailed else revstr ) or 'no revision' ))
2242
+ print "%s (%s)" % (prefix + (relpath (p_path , repo .path ) if p_path else repo .name ), ((repo .url + ('#' + str (repo .rev )[:12 ] if repo .rev else '' ) if detailed else repo . revtype ( repo . rev , fmt = 6 ) ) or 'no revision' ))
2232
2243
2233
2244
# Print list of tags
2234
2245
rprefix = (prefix [:- 3 ] + ('| ' if prefix [- 3 ] == '|' else ' ' )) if recursive and prefix else ''
0 commit comments