diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 290ca5802..582d777dd 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -216,7 +216,11 @@ class Git(Base): return [t.name for t in self.repo.tags] def _install_hook(self, name, cmd): - command = '[ -z "$(git ls-files .dvc)" ] || exec dvc {}'.format(cmd) + command = ( + '[ "$3" == "0" ]' + ' || [ -z "$(git ls-files .dvc)" ]' + " || exec dvc {}".format(cmd) + ) hook = os.path.join(self.root_dir, self.GIT_DIR, "hooks", name) diff --git a/tests/func/test_install.py b/tests/func/test_install.py index 140e0b5d5..1ff4ca23a 100644 --- a/tests/func/test_install.py +++ b/tests/func/test_install.py @@ -39,7 +39,9 @@ class TestInstall(object): expected_script = ( "#!/bin/sh\n" "echo hello\n" - '[ -z "$(git ls-files .dvc)" ] || exec dvc checkout\n' + '[ "$3" == "0" ]' + ' || [ -z "$(git ls-files .dvc)" ]' + " || exec dvc checkout\n" ) with open(self._hook("post-checkout"), "r") as fobj: @@ -51,7 +53,9 @@ class TestInstall(object): expected_script = ( "#!/bin/sh\n" - '[ -z "$(git ls-files .dvc)" ] || exec dvc checkout\n' + '[ "$3" == "0" ]' + ' || [ -z "$(git ls-files .dvc)" ]' + " || exec dvc checkout\n" ) with open(self._hook("post-checkout"), "r") as fobj: