Skip to content
Merged
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
27 changes: 19 additions & 8 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ def list_tags(self):
def list_all_commits(self):
return [c.hexsha for c in self.repo.iter_commits("--all")]

def _install_hook(self, name, cmd):
command = (
'[ "$3" = "0" ]'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was basically breaking other hooks previously, as it only makes sense for post-checkout.

' || [ -z "$(git ls-files --full-name .dvc)" ]'
" || exec dvc {}".format(cmd)
def _install_hook(self, name, preconditions, cmd):
# only run in dvc repo
in_dvc_repo = '[ -n "$(git ls-files --full-name .dvc)" ]'

command = "if {}; then exec dvc {}; fi".format(
" && ".join([in_dvc_repo] + preconditions), cmd
)

hook = self._hook_path(name)
Expand All @@ -269,9 +270,19 @@ def _install_hook(self, name, cmd):
def install(self):
self._verify_dvc_hooks()

self._install_hook("post-checkout", "checkout")
self._install_hook("pre-commit", "status")
self._install_hook("pre-push", "push")
self._install_hook(
"post-checkout",
[
# checking out some reference and not specific file.
'[ "$3" = "1" ]',
# check that we are on some branch/tag and not in detached HEAD
# state, so we don't accidentally break a rebase.
'[ "$(git rev-parse --abbrev-ref HEAD)" != "HEAD" ]',
],
"checkout",
)
self._install_hook("pre-commit", [], "status")
self._install_hook("pre-push", [], "push")

def cleanup_ignores(self):
for path in self.ignored_paths:
Expand Down