mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Rename some variables to be more like our internal state
This commit is contained in:
parent
36cfeac952
commit
f7b2948368
3 changed files with 10 additions and 25 deletions
|
|
@ -51,10 +51,6 @@ class Repository(object):
|
||||||
def repo_url(self):
|
def repo_url(self):
|
||||||
return self.repo_config['repo']
|
return self.repo_config['repo']
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def sha(self):
|
|
||||||
return self.repo_config['sha']
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def languages(self):
|
def languages(self):
|
||||||
return {
|
return {
|
||||||
|
|
@ -215,10 +211,6 @@ class LocalRepository(Repository):
|
||||||
def cmd_runner(self):
|
def cmd_runner(self):
|
||||||
return PrefixedCommandRunner(git.get_root())
|
return PrefixedCommandRunner(git.get_root())
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def sha(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def manifest(self):
|
def manifest(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,14 @@ class Store(object):
|
||||||
get_default_directory = staticmethod(_get_default_directory)
|
get_default_directory = staticmethod(_get_default_directory)
|
||||||
|
|
||||||
class RepoPathGetter(object):
|
class RepoPathGetter(object):
|
||||||
def __init__(self, repo, sha, store):
|
def __init__(self, repo, ref, store):
|
||||||
self._repo = repo
|
self._repo = repo
|
||||||
self._sha = sha
|
self._ref = ref
|
||||||
self._store = store
|
self._store = store
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def repo_path(self):
|
def repo_path(self):
|
||||||
return self._store.clone(self._repo, self._sha)
|
return self._store.clone(self._repo, self._ref)
|
||||||
|
|
||||||
def __init__(self, directory=None):
|
def __init__(self, directory=None):
|
||||||
if directory is None:
|
if directory is None:
|
||||||
|
|
@ -97,15 +97,15 @@ class Store(object):
|
||||||
self._create()
|
self._create()
|
||||||
self.__created = True
|
self.__created = True
|
||||||
|
|
||||||
def clone(self, url, sha):
|
def clone(self, url, ref):
|
||||||
"""Clone the given url and checkout the specific sha."""
|
"""Clone the given url and checkout the specific ref."""
|
||||||
self.require_created()
|
self.require_created()
|
||||||
|
|
||||||
# Check if we already exist
|
# Check if we already exist
|
||||||
with sqlite3.connect(self.db_path) as db:
|
with sqlite3.connect(self.db_path) as db:
|
||||||
result = db.execute(
|
result = db.execute(
|
||||||
'SELECT path FROM repos WHERE repo = ? AND ref = ?',
|
'SELECT path FROM repos WHERE repo = ? AND ref = ?',
|
||||||
[url, sha],
|
[url, ref],
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if result:
|
if result:
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
@ -118,18 +118,18 @@ class Store(object):
|
||||||
'git', 'clone', '--no-checkout', url, dir, env=no_git_env(),
|
'git', 'clone', '--no-checkout', url, dir, env=no_git_env(),
|
||||||
)
|
)
|
||||||
with cwd(dir):
|
with cwd(dir):
|
||||||
cmd_output('git', 'reset', sha, '--hard', env=no_git_env())
|
cmd_output('git', 'reset', ref, '--hard', env=no_git_env())
|
||||||
|
|
||||||
# Update our db with the created repo
|
# Update our db with the created repo
|
||||||
with sqlite3.connect(self.db_path) as db:
|
with sqlite3.connect(self.db_path) as db:
|
||||||
db.execute(
|
db.execute(
|
||||||
'INSERT INTO repos (repo, ref, path) VALUES (?, ?, ?)',
|
'INSERT INTO repos (repo, ref, path) VALUES (?, ?, ?)',
|
||||||
[url, sha, dir],
|
[url, ref, dir],
|
||||||
)
|
)
|
||||||
return dir
|
return dir
|
||||||
|
|
||||||
def get_repo_path_getter(self, repo, sha):
|
def get_repo_path_getter(self, repo, ref):
|
||||||
return self.RepoPathGetter(repo, sha, self)
|
return self.RepoPathGetter(repo, ref, self)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def cmd_runner(self):
|
def cmd_runner(self):
|
||||||
|
|
|
||||||
|
|
@ -458,11 +458,6 @@ def test_repo_url(mock_repo_config):
|
||||||
assert repo.repo_url == 'git@github.com:pre-commit/pre-commit-hooks'
|
assert repo.repo_url == 'git@github.com:pre-commit/pre-commit-hooks'
|
||||||
|
|
||||||
|
|
||||||
def test_sha(mock_repo_config):
|
|
||||||
repo = Repository(mock_repo_config, None)
|
|
||||||
assert repo.sha == '5e713f8878b7d100c0e059f8cc34be4fc2e8f897'
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_languages(tempdir_factory, store):
|
def test_languages(tempdir_factory, store):
|
||||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
|
|
@ -684,8 +679,6 @@ def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
|
||||||
def test_local_repository():
|
def test_local_repository():
|
||||||
config = config_with_local_hooks()
|
config = config_with_local_hooks()
|
||||||
local_repo = Repository.create(config, 'dummy')
|
local_repo = Repository.create(config, 'dummy')
|
||||||
with pytest.raises(NotImplementedError):
|
|
||||||
local_repo.sha
|
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
local_repo.manifest
|
local_repo.manifest
|
||||||
assert len(local_repo.hooks) == 1
|
assert len(local_repo.hooks) == 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue