Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't dvc checkout on git file checkout #2403

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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