diff --git a/hggit/__init__.py b/hggit/__init__.py index f5dc1730e4d30ee1ffe773424d3c572f4fe0da83_aGdnaXQvX19pbml0X18ucHk=..6507d2a6be0a1170282b0cd49b419c90e62da558_aGdnaXQvX19pbml0X18ucHk= 100644 --- a/hggit/__init__.py +++ b/hggit/__init__.py @@ -75,8 +75,7 @@ # support for `hg clone git://github.com/defunkt/facebox.git` # also hg clone git+ssh://git@github.com/schacon/simplegit.git -_gitschemes = ('git', 'git+ssh', 'git+http', 'git+https') -for _scheme in _gitschemes: +for _scheme in util.gitschemes: hg.schemes[_scheme] = gitrepo # support for `hg clone localgitrepo` @@ -109,5 +108,5 @@ hgdefaultdest = hg.defaultdest def defaultdest(source): - for scheme in _gitschemes: + for scheme in util.gitschemes: if source.startswith('%s://' % scheme) and source.endswith('.git'): @@ -113,6 +112,9 @@ if source.startswith('%s://' % scheme) and source.endswith('.git'): - source = source[:-4] - break + return hgdefaultdest(source[:-4]) + + if source.endswith('.git'): + return hgdefaultdest(source[:-4]) + return hgdefaultdest(source) hg.defaultdest = defaultdest diff --git a/hggit/util.py b/hggit/util.py index f5dc1730e4d30ee1ffe773424d3c572f4fe0da83_aGdnaXQvdXRpbC5weQ==..6507d2a6be0a1170282b0cd49b419c90e62da558_aGdnaXQvdXRpbC5weQ== 100644 --- a/hggit/util.py +++ b/hggit/util.py @@ -1,5 +1,7 @@ """Compatibility functions for old Mercurial versions and other utility functions.""" +import re + from dulwich import errors from mercurial import util as hgutil try: @@ -7,6 +9,8 @@ except ImportError: from ordereddict import OrderedDict +gitschemes = ('git', 'git+ssh', 'git+http', 'git+https') + def parse_hgsub(lines): """Fills OrderedDict with hgsub file content passed as list of lines""" rv = OrderedDict() @@ -45,3 +49,43 @@ except errors.NotGitRepository: raise hgutil.Abort('not a git repository') return inner + +def isgitsshuri(uri): + """Method that returns True if a uri looks like git-style uri + + Tests: + + >>> print isgitsshuri('http://fqdn.com/hg') + False + >>> print isgitsshuri('http://fqdn.com/test.git') + False + >>> print isgitsshuri('git@github.com:user/repo.git') + True + >>> print isgitsshuri('github-123.com:user/repo.git') + True + >>> print isgitsshuri('git@127.0.0.1:repo.git') + True + >>> print isgitsshuri('git@[2001:db8::1]:repository.git') + True + """ + for scheme in gitschemes: + if uri.startswith('%s://' % scheme): + return False + + if uri.startswith('http:') or uri.startswith('https:'): + return False + + m = re.match(r'(?:.+@)*([\[]?[\w\d\.\:\-]+[\]]?):(.*)', uri) + if m: + # here we're being fairly conservative about what we consider to be git + # urls + giturl, repopath = m.groups() + # definitely a git repo + if repopath.endswith('.git'): + return True + # use a simple regex to check if it is a fqdn regex + fqdn_re = (r'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}' + r'(?<!-)\.)+[a-zA-Z]{2,63}$)') + if re.match(fqdn_re, giturl): + return True + return False