Skip to content

Commit

Permalink
Merge pull request #2403 from gthb/no-dvc-checkout-on-git-file-checkout
Browse files Browse the repository at this point in the history
fix: don't dvc checkout on git file checkout
  • Loading branch information
efiop authored Aug 19, 2019
2 parents 30a7b77 + e1dd75e commit 239739d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,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)

Expand Down
8 changes: 6 additions & 2 deletions tests/func/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 239739d

Please sign in to comment.