pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.87k stars 175 forks source link

Pre-commit hook #447

Open real-yfprojects opened 1 year ago

real-yfprojects commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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.