mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-12-02 15:28:29 +01:00
dvc: hooks only act in branches where dvc active (#2338)
* dvc: hooks only act in branches where dvc active In a branch where DVC hasn't been initialized (as detected by `git ls-files .dvc` not listing any files), don't invoke dvc in the git hooks. This avoids trouble when switching between branches with and without dvc initialized. Fixes #2208 * dvc: simplify hooks per PR comment
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
df0359fad0
commit
e917ce0ae8
@@ -216,19 +216,17 @@ class Git(Base):
|
||||
return [t.name for t in self.git.tags]
|
||||
|
||||
def _install_hook(self, name, cmd):
|
||||
command = "dvc {}".format(cmd)
|
||||
command = '[ -z "$(git ls-files .dvc)" ] || exec dvc {}'.format(cmd)
|
||||
|
||||
hook = os.path.join(self.root_dir, self.GIT_DIR, "hooks", name)
|
||||
|
||||
if os.path.isfile(hook):
|
||||
with open(hook, "r+") as fobj:
|
||||
if command not in fobj.read():
|
||||
fobj.write("exec {command}\n".format(command=command))
|
||||
fobj.write("{command}\n".format(command=command))
|
||||
else:
|
||||
with open(hook, "w+") as fobj:
|
||||
fobj.write(
|
||||
"#!/bin/sh\n" "exec {command}\n".format(command=command)
|
||||
)
|
||||
fobj.write("#!/bin/sh\n" "{command}\n".format(command=command))
|
||||
|
||||
os.chmod(hook, 0o777)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user