diff --git a/dvc/scm.py b/dvc/scm.py index 742feb4f7..5230d00a0 100644 --- a/dvc/scm.py +++ b/dvc/scm.py @@ -240,18 +240,22 @@ class Git(Base): def list_tags(self): return [t.name for t in self.repo.tags] - def install(self): + def _install_hook(self, name, cmd): hook = os.path.join(self.root_dir, self.GIT_DIR, 'hooks', - 'post-checkout') + name) if os.path.isfile(hook): msg = 'Git hook \'{}\' already exists.' raise SCMError(msg.format(os.path.relpath(hook))) with open(hook, 'w+') as fd: - fd.write('#!/bin/sh\nexec dvc checkout\n') + fd.write('#!/bin/sh\nexec dvc {}\n'.format(cmd)) os.chmod(hook, 0o777) + def install(self): + self._install_hook('post-checkout', 'checkout') + self._install_hook('pre-commit', 'status') + def SCM(root_dir, no_scm=False, project=None): if Git.is_repo(root_dir) or Git.is_submodule(root_dir): diff --git a/tests/test_install.py b/tests/test_install.py index 28b67095f..a94458cb7 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -13,7 +13,11 @@ class TestInstall(TestDvc): ret = main(['install']) self.assertNotEqual(ret, 0) - self.assertTrue(os.path.isfile('.git/hooks/post-checkout')) + def hook(name): + return os.path.join('.git', 'hooks', name) + + self.assertTrue(os.path.isfile(hook('post-checkout'))) + self.assertTrue(os.path.isfile(hook('pre-commit'))) self.dvc.add(self.FOO) os.unlink(self.FOO)