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

Pre-commit hook #447

Open
real-yfprojects opened this issue Feb 19, 2023 · 4 comments
Open

Pre-commit hook #447

real-yfprojects opened this issue Feb 19, 2023 · 4 comments

Comments

@real-yfprojects
Copy link

real-yfprojects commented Feb 19, 2023

I would like to use doit as a pre-commit hook. I have a couple of 'build' tasks that generate source files. These source files should be present and also up-to-date in each commit. Not only doesn't doit provide its own .pre-commit-hooks.yaml file, but i can't define my own hook using doit since doit will always return code 0. I would like to have an option which makes doit fail if one of the tasks run modified a file. Also I would like doit to provide a pre-configured pre-commit hook.

Fund with Polar
@schettino72
Copy link
Member

doit does NOT always return 0. If a task fails it returns non-zero.

It seems you want a non-zero return code if any task is actually executed (not up-to-date). is that it? currently not possible but should not be hard to achieve this somehow...

Regarding pre-commit package. I am not familiar with the project implementation.
doit was designed to be executed many times during development cycle, not once on commit.
But I get it would be trivial to just invoke doit in a pre-commit hook.

@real-yfprojects
Copy link
Author

It seems you want a non-zero return code if any task is actually executed (not up-to-date). is that it? currently not possible but should not be hard to achieve this somehow...

Yes, exactly. There would be two possible modes for such a hook. A mode that only checks that everything is up-to-date and doesn't modify any files. And a mode that actually runs the tasks.
I would prefer to use the second option. However the first option would work too since I could run doit manually if the pre-commit check fails. This would therefore be the more versatile option.

Regarding pre-commit package. I am not familiar with the project implementation.

You define how to run your hook in a small .pre-commit-hooks.yaml file. I could write such a file if above functionality is in place.

doit was designed to be executed many times during development cycle, not once on commit.

That isn't a problem since the hook can be used additionally to running doit manually.

@ernieIzde8ski
Copy link

Yes, exactly.

What use-case is this, exactly? The pre-commit utility aborts commits if any tracked files are changed, on top of aborting commits when subprocesses exit with non-zero status codes. Is there a use-case where you need doit to fail on untracked but successful builds?

@real-yfprojects
Copy link
Author

I am unsure what you mean. I use doit to perform certain automated tasks on which files change. These tasks are necessary for a valid repository state. Thus I'd like to add a pre-commit hook, that ensures that commits cannot be created containing partial states on which doit was't run yet. I feel like that would be a common use case. It's the same as running a code formatter before every commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants