dvc
dvc copied to clipboard
Add exit code for pre-commit hook
When running the pre-commit hook I would like it to fail if there are updates to files tracked by DVC, at the moment I get the status message but pre-commit completes and I cannot "force" people to run dvc commit
prior to running git commit
. I can get the exit code from the command line via dvc status -q
but not within pre-commit.
Ideally I would like the hook to look something like,
- repo: https://github.com/iterative/dvc
rev: 2.12.0
hooks:
- id: dvc-pre-commit
language_version: python3
stages:
- commit
args:
- -q
I don't need the status message (it would be nice but not a requirement), users can run dvc status
to get that afterwards.
@ralphbird Do you have a workaround for that for the time being? Would the usual git-hook suffice? Something like:
#!/bin/bash
dvc status -q
exit_code=$?
if [ $exit_code>=1 ];
then
echo 'Commit failed, DVC has uncommited data'
fi
exit $exit_code
In your .git/hooks/pre-commit
Hello, the pre-commit hook is still not failing when there are uncommitted files. Please @mattseddon give more instructions on how to configure to allow it to fail