diff --git a/pre_commit/store.py b/pre_commit/store.py index 93a9cab3..d1d432dc 100644 --- a/pre_commit/store.py +++ b/pre_commit/store.py @@ -138,7 +138,7 @@ class Store(object): def _complete_clone(self, ref, git_cmd): """Perform a complete clone of a repository and its submodules """ - git_cmd('fetch', 'origin') + git_cmd('fetch', 'origin', '--tags') git_cmd('checkout', ref) git_cmd('submodule', 'update', '--init', '--recursive') diff --git a/tests/store_test.py b/tests/store_test.py index 66217588..1833dee7 100644 --- a/tests/store_test.py +++ b/tests/store_test.py @@ -13,6 +13,7 @@ from pre_commit import git from pre_commit.store import _get_default_directory from pre_commit.store import Store from pre_commit.util import CalledProcessError +from pre_commit.util import cmd_output from testing.fixtures import git_dir from testing.util import cwd from testing.util import git_commit @@ -147,6 +148,20 @@ def test_clone_shallow_failure_fallback_to_complete( assert store.select_all_repos() == [(path, rev, ret)] +def test_clone_tag_not_on_mainline(store, tempdir_factory): + path = git_dir(tempdir_factory) + with cwd(path): + git_commit() + cmd_output('git', 'checkout', 'master', '-b', 'branch') + git_commit() + cmd_output('git', 'tag', 'v1') + cmd_output('git', 'checkout', 'master') + cmd_output('git', 'branch', '-D', 'branch') + + # previously crashed on unreachable refs + store.clone(path, 'v1') + + def test_create_when_directory_exists_but_not_db(store): # In versions <= 0.3.5, there was no sqlite db causing a need for # backward compatibility