mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
install: add pre-checkout hook
Fixes #1248 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+7
-3
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user