Rename some variables to be more like our internal state

This commit is contained in:
Anthony Sottile
2017-02-15 08:57:10 -08:00
parent 36cfeac952
commit f7b2948368
3 changed files with 10 additions and 25 deletions

View File

@@ -51,10 +51,6 @@ class Repository(object):
def repo_url(self):
return self.repo_config['repo']
@cached_property
def sha(self):
return self.repo_config['sha']
@cached_property
def languages(self):
return {
@@ -215,10 +211,6 @@ class LocalRepository(Repository):
def cmd_runner(self):
return PrefixedCommandRunner(git.get_root())
@cached_property
def sha(self):
raise NotImplementedError
@cached_property
def manifest(self):
raise NotImplementedError

View File

@@ -36,14 +36,14 @@ class Store(object):
get_default_directory = staticmethod(_get_default_directory)
class RepoPathGetter(object):
def __init__(self, repo, sha, store):
def __init__(self, repo, ref, store):
self._repo = repo
self._sha = sha
self._ref = ref
self._store = store
@cached_property
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):
if directory is None:
@@ -97,15 +97,15 @@ class Store(object):
self._create()
self.__created = True
def clone(self, url, sha):
"""Clone the given url and checkout the specific sha."""
def clone(self, url, ref):
"""Clone the given url and checkout the specific ref."""
self.require_created()
# Check if we already exist
with sqlite3.connect(self.db_path) as db:
result = db.execute(
'SELECT path FROM repos WHERE repo = ? AND ref = ?',
[url, sha],
[url, ref],
).fetchone()
if result:
return result[0]
@@ -118,18 +118,18 @@ class Store(object):
'git', 'clone', '--no-checkout', url, dir, env=no_git_env(),
)
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
with sqlite3.connect(self.db_path) as db:
db.execute(
'INSERT INTO repos (repo, ref, path) VALUES (?, ?, ?)',
[url, sha, dir],
[url, ref, dir],
)
return dir
def get_repo_path_getter(self, repo, sha):
return self.RepoPathGetter(repo, sha, self)
def get_repo_path_getter(self, repo, ref):
return self.RepoPathGetter(repo, ref, self)
@cached_property
def cmd_runner(self):

View File

@@ -458,11 +458,6 @@ def test_repo_url(mock_repo_config):
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
def test_languages(tempdir_factory, store):
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():
config = config_with_local_hooks()
local_repo = Repository.create(config, 'dummy')
with pytest.raises(NotImplementedError):
local_repo.sha
with pytest.raises(NotImplementedError):
local_repo.manifest
assert len(local_repo.hooks) == 1