Merge pull request #247 from dkunitsk/master

fix for issue 246
This commit is contained in:
Anthony Sottile
2015-07-20 18:23:57 -07:00
3 changed files with 20 additions and 1 deletions

View File

@@ -27,10 +27,14 @@ IDENTIFYING_HASH = '79f09a650522a87b0da915d0d983b2de'
def is_our_pre_commit(filename):
if not os.path.exists(filename):
return False
return IDENTIFYING_HASH in io.open(filename).read()
def is_previous_pre_commit(filename):
if not os.path.exists(filename):
return False
contents = io.open(filename).read()
return any(hash in contents for hash in PREVIOUS_IDENTIFYING_HASHES)
@@ -53,7 +57,7 @@ def install(runner, overwrite=False, hooks=False, hook_type='pre-commit'):
# If we have an existing hook, move it to pre-commit.legacy
if (
os.path.exists(hook_path) and
os.path.lexists(hook_path) and
not is_our_pre_commit(hook_path) and
not is_previous_pre_commit(hook_path)
):

View File

@@ -73,3 +73,8 @@ xfailif_no_pcre_support = pytest.mark.xfail(
not platform_supports_pcre(),
reason='grep -P is not supported on this platform',
)
xfailif_no_symlink = pytest.mark.xfail(
not hasattr(os, 'symlink'),
reason='Symlink is not supported on this platform',
)

View File

@@ -24,6 +24,7 @@ from pre_commit.util import cwd
from pre_commit.util import resource_filename
from testing.fixtures import git_dir
from testing.fixtures import make_consuming_repo
from testing.util import xfailif_no_symlink
def test_is_not_our_pre_commit():
@@ -88,6 +89,15 @@ def test_install_hooks_directory_not_present(tmpdir_factory):
assert os.path.exists(runner.pre_commit_path)
@xfailif_no_symlink
def test_install_hooks_dead_symlink(tmpdir_factory):
path = git_dir(tmpdir_factory)
os.symlink('/fake/baz', os.path.join(path, '.git', 'hooks', 'pre-commit'))
runner = Runner(path)
install(runner)
assert os.path.exists(runner.pre_commit_path)
def test_uninstall_does_not_blow_up_when_not_there(tmpdir_factory):
path = git_dir(tmpdir_factory)
runner = Runner(path)