Merge pull request #629 from pre-commit/more_realistic_test_clones

Use file:// protocol for cloning under test
This commit is contained in:
Anthony Sottile 2017-09-22 11:04:37 -07:00 committed by GitHub
commit 3a7806ea30
4 changed files with 7 additions and 3 deletions

View file

@ -37,8 +37,11 @@ def in_env(repo_cmd_runner):
def guess_go_dir(remote_url): def guess_go_dir(remote_url):
if remote_url.endswith('.git'): if remote_url.endswith('.git'):
remote_url = remote_url[:-1 * len('.git')] remote_url = remote_url[:-1 * len('.git')]
looks_like_url = (
not remote_url.startswith('file://') and
('//' in remote_url or '@' in remote_url)
)
remote_url = remote_url.replace(':', '/') remote_url = remote_url.replace(':', '/')
looks_like_url = '//' in remote_url or '@' in remote_url
if looks_like_url: if looks_like_url:
_, _, remote_url = remote_url.rpartition('//') _, _, remote_url = remote_url.rpartition('//')
_, _, remote_url = remote_url.rpartition('@') _, _, remote_url = remote_url.rpartition('@')

View file

@ -83,7 +83,7 @@ def config_with_local_hooks():
def make_config_from_repo(repo_path, sha=None, hooks=None, check=True): def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE)) manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
config = OrderedDict(( config = OrderedDict((
('repo', repo_path), ('repo', 'file://{}'.format(repo_path)),
('sha', sha or get_head_sha(repo_path)), ('sha', sha or get_head_sha(repo_path)),
( (
'hooks', 'hooks',

View file

@ -10,6 +10,7 @@ from pre_commit.languages.golang import guess_go_dir
('url', 'expected'), ('url', 'expected'),
( (
('/im/a/path/on/disk', 'unknown_src_dir'), ('/im/a/path/on/disk', 'unknown_src_dir'),
('file:///im/a/path/on/disk', 'unknown_src_dir'),
('git@github.com:golang/lint', 'github.com/golang/lint'), ('git@github.com:golang/lint', 'github.com/golang/lint'),
('git://github.com/golang/lint', 'github.com/golang/lint'), ('git://github.com/golang/lint', 'github.com/golang/lint'),
('http://github.com/golang/lint', 'github.com/golang/lint'), ('http://github.com/golang/lint', 'github.com/golang/lint'),

View file

@ -714,7 +714,7 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
with pytest.raises(SystemExit): with pytest.raises(SystemExit):
repo.require_installed() repo.require_installed()
assert fake_log_handler.handle.call_args[0][0].msg == ( assert fake_log_handler.handle.call_args[0][0].msg == (
'`i-dont-exist` is not present in repository {}. ' '`i-dont-exist` is not present in repository file://{}. '
'Typo? Perhaps it is introduced in a newer version? ' 'Typo? Perhaps it is introduced in a newer version? '
'Often `pre-commit autoupdate` fixes this.'.format(path) 'Often `pre-commit autoupdate` fixes this.'.format(path)
) )