Merge pull request #382 from pre-commit/tags_when_available

Autoupdate to tags when available
This commit is contained in:
Anthony Sottile
2016-06-23 09:56:33 -07:00
committed by GitHub
2 changed files with 29 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ from pre_commit.jsonschema_extensions import remove_defaults
from pre_commit.logging_handler import LoggingHandler
from pre_commit.ordereddict import OrderedDict
from pre_commit.repository import Repository
from pre_commit.util import CalledProcessError
from pre_commit.util import cmd_output
from pre_commit.util import cwd
@@ -38,15 +39,20 @@ def _update_repository(repo_config, runner):
with cwd(repo.repo_path_getter.repo_path):
cmd_output('git', 'fetch')
head_sha = cmd_output('git', 'rev-parse', 'origin/master')[1].strip()
try:
rev = cmd_output(
'git', 'describe', 'origin/master', '--tags', '--exact',
)[1].strip()
except CalledProcessError:
rev = cmd_output('git', 'rev-parse', 'origin/master')[1].strip()
# Don't bother trying to update if our sha is the same
if head_sha == repo_config['sha']:
if rev == repo_config['sha']:
return repo_config
# Construct a new config with the head sha
new_config = OrderedDict(repo_config)
new_config['sha'] = head_sha
new_config['sha'] = rev
new_repo = Repository.create(new_config, runner.store)
# See if any of our hooks were deleted with the new commits

View File

@@ -96,6 +96,26 @@ def test_autoupdate_out_of_date_repo(
assert out_of_date_repo.head_sha in after
@pytest.yield_fixture
def tagged_repo(out_of_date_repo):
with cwd(out_of_date_repo.path):
cmd_output('git', 'tag', 'v1.2.3')
yield out_of_date_repo
def test_autoupdate_tagged_repo(
tagged_repo, in_tmpdir, mock_out_store_directory,
):
config = make_config_from_repo(
tagged_repo.path, sha=tagged_repo.original_sha,
)
write_config('.', config)
ret = autoupdate(Runner('.'))
assert ret == 0
assert 'v1.2.3' in open(C.CONFIG_FILE).read()
@pytest.yield_fixture
def hook_disappearing_repo(tempdir_factory):
path = make_repo(tempdir_factory, 'python_hooks_repo')