From e1dd75edcd0e219000b818b5cd646bac19136340 Mon Sep 17 00:00:00 2001 From: Gunnlaugur Thor Briem Date: Fri, 16 Aug 2019 22:11:16 +0000 Subject: [PATCH] fix: don't dvc checkout on git file checkout Closes #2400 --- dvc/scm/git/__init__.py | 6 +++++- tests/func/test_install.py | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 290ca58020..582d777dd8 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -216,7 +216,11 @@ def list_tags(self): 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 140e0b5d54..1ff4ca23a4 100644 --- a/tests/func/test_install.py +++ b/tests/func/test_install.py @@ -39,7 +39,9 @@ def test_should_append_hooks_if_file_already_exists(self, git, dvc_repo): 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 @@ def test_should_be_idempotent(self, git, dvc_repo): 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: