mirror of
https://github.com/facebook/sapling.git
synced 2024-10-16 11:52:02 +03:00
9dc21f8d0b
Summary: D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`. That has nasty problems if both `import mercurial` and `import edenscm.mercurial` are used, because Python would think `mercurial.foo` and `edenscm.mercurial.foo` are different modules so code like `try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)` would fail to handle the `edenscm.mercurial` version. There are also some module-level states (ex. `extensions._extensions`) that would cause trouble if they have multiple versions in a single process. Change imports to use the `edenscm` so ideally the `mercurial` is no longer imported at all. Add checks in extensions.py to catch unexpected extensions importing modules from the old (wrong) locations when running tests. Reviewed By: phillco Differential Revision: D13868981 fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
import shutil
|
|
import sys
|
|
import tempfile
|
|
|
|
from edenscm.hgext.hggit.git_handler import GitHandler
|
|
from edenscm.mercurial import commands, hg, ui
|
|
|
|
|
|
try:
|
|
import dulwich
|
|
|
|
type(dulwich) # avoid pyflakes unused import error
|
|
except ImportError:
|
|
print("skipped: missing feature: dulwich")
|
|
sys.exit(80)
|
|
|
|
|
|
class TestUrlParsing(object):
|
|
def setUp(self):
|
|
# create a test repo location.
|
|
self.tmpdir = tempfile.mkdtemp("hg-git_url-test")
|
|
commands.init(ui.ui(), self.tmpdir)
|
|
repo = hg.repository(ui.ui(), self.tmpdir)
|
|
self.handler = GitHandler(repo, ui.ui())
|
|
|
|
def tearDown(self):
|
|
# remove the temp repo
|
|
shutil.rmtree(self.tmpdir)
|
|
|
|
def assertEquals(self, l, r):
|
|
print("%% expect %r" % (r,))
|
|
print(l)
|
|
assert l == r
|
|
|
|
def test_ssh_github_style_slash(self):
|
|
url = "git+ssh://git@github.com/webjam/webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
self.assertEquals(client.host, "git@github.com")
|
|
|
|
def test_ssh_github_style_colon_number_starting_username(self):
|
|
url = "git+ssh://git@github.com:42qu/vps.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "42qu/vps.git")
|
|
self.assertEquals(client.host, "git@github.com")
|
|
|
|
def test_ssh_github_style_colon(self):
|
|
url = "git+ssh://git@github.com:webjam/webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "webjam/webjam.git")
|
|
self.assertEquals(client.host, "git@github.com")
|
|
|
|
def test_ssh_heroku_style(self):
|
|
url = "git+ssh://git@heroku.com:webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "webjam.git")
|
|
self.assertEquals(client.host, "git@heroku.com")
|
|
# also test that it works even if heroku isn't in the name
|
|
url = "git+ssh://git@compatible.com:webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "webjam.git")
|
|
self.assertEquals(client.host, "git@compatible.com")
|
|
|
|
def test_ssh_heroku_style_with_trailing_slash(self):
|
|
# some versions of mercurial add a trailing slash even if
|
|
# the user didn't supply one.
|
|
url = "git+ssh://git@heroku.com:webjam.git/"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "webjam.git")
|
|
self.assertEquals(client.host, "git@heroku.com")
|
|
|
|
def test_heroku_style_with_port(self):
|
|
url = "git+ssh://git@heroku.com:999:webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "webjam.git")
|
|
self.assertEquals(client.host, "git@heroku.com")
|
|
self.assertEquals(client.port, "999")
|
|
|
|
def test_gitdaemon_style(self):
|
|
url = "git://github.com/webjam/webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
try:
|
|
self.assertEquals(client._host, "github.com")
|
|
except AttributeError:
|
|
self.assertEquals(client.host, "github.com")
|
|
|
|
def test_ssh_github_style_slash_with_port(self):
|
|
url = "git+ssh://git@github.com:10022/webjam/webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
self.assertEquals(client.host, "git@github.com")
|
|
self.assertEquals(client.port, "10022")
|
|
|
|
def test_gitdaemon_style_with_port(self):
|
|
url = "git://github.com:19418/webjam/webjam.git"
|
|
client, path = self.handler.get_transport_and_path(url)
|
|
self.assertEquals(path, "/webjam/webjam.git")
|
|
try:
|
|
self.assertEquals(client._host, "github.com")
|
|
except AttributeError:
|
|
self.assertEquals(client.host, "github.com")
|
|
self.assertEquals(client._port, "19418")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
tc = TestUrlParsing()
|
|
for test in sorted([t for t in dir(tc) if t.startswith("test_")]):
|
|
tc.setUp()
|
|
getattr(tc, test)()
|
|
tc.tearDown()
|