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

Use as a pre-push hook #55

Open
gaul opened this issue Feb 7, 2018 · 2 comments
Open

Use as a pre-push hook #55

gaul opened this issue Feb 7, 2018 · 2 comments
Labels
enhancement User-facing feature enhancements

Comments

@gaul
Copy link

gaul commented Feb 7, 2018

Can I use gitlint as a pre-push hook? It matched some unexpected data:

$ git push origin gitlint
1: T1 Title exceeds max length (119>72): "refs/heads/gitlint 28532b3925ae8c54af2d0012638688e4f1cfd203 refs/heads/gitlint 0000000000000000000000000000000000000000"
1: T7 Title does not match regex (.*\.$): "refs/heads/gitlint 28532b3925ae8c54af2d0012638688e4f1cfd203 refs/heads/gitlint 0000000000000000000000000000000000000000"
error: failed to push some refs to 'git@github.com:gaul/repo.git'
gaul added a commit to gaul/gitlint that referenced this issue Mar 29, 2018
gaul added a commit to gaul/gitlint that referenced this issue Mar 29, 2018
@jorisroovers jorisroovers added the enhancement User-facing feature enhancements label Mar 30, 2018
gaul added a commit to gaul/gitlint that referenced this issue Apr 6, 2018
gaul added a commit to gaul/gitlint that referenced this issue Apr 6, 2018
gaul added a commit to gaul/gitlint that referenced this issue Apr 6, 2018
gaul added a commit to gaul/gitlint that referenced this issue Apr 10, 2018
@jorisroovers
Copy link
Owner

jorisroovers commented Apr 15, 2018

So I looked into this a bit more and think gitlint actually supports this out of the box already, perhaps with a small caveat.

See http://jorisroovers.github.io/gitlint/#linting-a-range-of-commits

You can use gitlint to lint a single sha like so:

SHA="f0c4acf161a23f37c8af8985d281254822280227"
gitlint --commits ${SHA}^...${SHA}
# I've noticed that there's a mistake in the docs, since it says you can just do 'gitlint --commits ${SHA}' to lint a single commit.
# In reality, that will lint all commits in the repo that occured before (and incl) that particular commit (this is inline with git's refspec defintion).
# I'll fix the docs on that.

This will also work if you want to specific a range of commits (which I'm thinking is what you'd really want):

gitlint --commits ${START_SHA}...${END_SHA}

The caveat is that if you want to lint a specific set of non-consecutive shas, you'll have to write a for loop:

for sha in f0c4acf161a23f37c8af8985d281254822280227 03eec2042d97a4414b45e0f5f7e67fa85ce9f80b 2a05f1b12bcc830c5d2da93d180230e1f74922dd; do
   gitlint --debug --commits ${sha}^...${sha}
done

I've thought before about adding support for comma-separated sha lists to gitlint, but haven't gotten to it yet.
That would work like so:

gitlint --commits <sha1>,<sha2>,<sha3>

As an FYI, if there's still a case for adding in PR #61, then it will need some changes - in particular wrt the tests, these should be added to the other integration tests in the qa directory and not as a special case in ./run_tests.sh.

I was planning on quickly doing that myself, but than figured out that this PR is likely not needed as per the above. I pushed the work I already did to the issues/61 branch for future reference.

Hope this helps!

@gaul
Copy link
Author

gaul commented Apr 17, 2018

The caveat is that if you want to lint a specific set of non-consecutive shas, you'll have to write a for loop:

The only difference is whether the loop is inside gitlint or the in pre-push script, as the small addition to cli.py demonstrates. Linting on pre-push is the primary use case for my projects and something I expect out of box. For example I run all my compilation and style checks in this manner. However, if you do not want to directly support this use case please close this issue and the related pull request.

rettichschnidi added a commit to husqvarnagroup/wakaama that referenced this issue Apr 26, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
rettichschnidi added a commit to husqvarnagroup/wakaama that referenced this issue Apr 26, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
rettichschnidi added a commit to husqvarnagroup/wakaama that referenced this issue Apr 26, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
rettichschnidi added a commit to rettichschnidi/wakaama that referenced this issue Apr 26, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
rettichschnidi added a commit to rettichschnidi/wakaama that referenced this issue Apr 26, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
rettichschnidi added a commit to eclipse-wakaama/wakaama that referenced this issue Apr 27, 2021
Doing so gives the developer feedback early on, before the changes hit
the GitHub CI infrastructure.

This would be a good candidate for using a Git pre-hook. Unfortunately,
gitlint is a bit tricky to be used in a pre-push hook:
jorisroovers/gitlint#55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement User-facing feature enhancements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants