modulesync icon indicating copy to clipboard operation
modulesync copied to clipboard

Allow pre-commit script to exist outside of modulesync Gem

Open btsibr opened this issue 7 years ago • 5 comments

The pre-commit script shouldn't need to be inside of modulesync itself (instead of forcing it to be in contrib).

At the simplest, if given an absolute path it should run that.

The primary use case here is that we have modulesync creating shell scripts and need to be able to chmod them prior to commit.

btsibr avatar Aug 07 '17 14:08 btsibr

see also #148

steinbrueckri avatar Jan 20 '20 14:01 steinbrueckri

Could someone describe a real-life example where its useful to use a pre commit hook in msync context? This way, we can write a behavior test and fix this issue accordingly.

Thanks

neomilium avatar Apr 23 '21 11:04 neomilium

One use case is coding style checkers. For example, you can run rubocop with -a to automatically fix style errors. puppet-lint has a similar operation.

Then there are 2 ways of dealing with that. First of all, it could be part of the "modulesync x.y.z" commit. However, I personally think a separate "autofix" commit makes more sense and makes reviewing easier. That would give a need for a post-commit hook.

Another could be to run a rake task, like validate. For example, I can imagine you want to verify you generated valid Ruby code in a template. bundle update must succeed comes to mind.

ekohl avatar Apr 23 '21 11:04 ekohl

Regarding our discussion about lightweight of the msync, is this pre hook commit is not an overkill feature if we have an exec and push atomic command?

If pre commit hook stays interesting, what about rely on git hooks?

ATM, it seems almost no one use this feature as there is only one available script, "hardcoded" is repo.

My first though is to drop this feature... just waiting to be convinced it make sense to (really) integrate it in msync code base.

neomilium avatar Apr 23 '21 11:04 neomilium

Thinking about this, I purpose a solution that looks better to me:

What about allowing user to specify hooks in configuration files?

Details: I think we could implement a way to install hooks, globally or per-module defined, and rely on git hooks features to run the user specified hooks.

Example:

---
puppet-hello:
  hooks:
    pre_commit: '/usr/bin/true'
    pre_push: 'bundle update'

neomilium avatar Apr 24 '21 08:04 neomilium