Opened 8 years ago
Last modified 7 years ago
#52770 new enhancement
Git: pre-commit hook for 'port lint' if a Portfile is about to be committed
Reported by: | mkae (Marko Käning) | Owned by: | admin@… |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | server/hosting | Version: | 2.3.4 |
Keywords: | Cc: | ||
Port: |
Description
... which could potentially avoid Portfile errors and warnings right from the start.
- Errors should lead to a strict cancellation of the commit.
- Warnings might be ignored, but one could also think of some interactive feedback loop - regarding how to proceed - in order to motivate users to adhere to Portfile guidelines.
Change History (9)
comment:1 follow-up: 4 Changed 8 years ago by mkae (Marko Käning)
comment:2 Changed 8 years ago by mkae (Marko Käning)
A nice example where such a hook would have been helpful is e.g. this failed build which could have been prevented if port lint
would have spotted the issue with an incomplete argument for depends_lib-append
, see this diff:
- depends_lib-append qt5-qtsvg + depends_lib-append port:qt5-qtsvg
The latter had to be fixed in the subsequent commit.
comment:3 Changed 8 years ago by mkae (Marko Käning)
A test showed, that port lint
would have spotted this:
$ port lint qtcurve-qt5 Error: Unable to open port: can't set "depends_lib": invalid depspec: qt5-qtsvg
comment:4 follow-up: 5 Changed 8 years ago by larryv (Lawrence Velázquez)
Replying to mkae:
This hook functionality could probably be implemented as a plugin directly on GitHub
I’m fairly sure that GitHub does not provide this functionality.
comment:5 Changed 8 years ago by mkae (Marko Käning)
Replying to larryv:
I’m fairly sure that GitHub does not provide this functionality.
Surely not directly on GitHub, Larry, but triggered from there on the buildbots or a dedicated lintbot perhaps.
comment:6 Changed 8 years ago by raimue (Rainer Müller)
When you start with WebHooks this sounds like a different use case and you are not talking about a pre-commit hook anymore.
Yes, port lint
for pull requests would be nice to have. I previously suggested this on macports-dev to explore using Travis CI for this, as they offer the required isolated environment, which is not provided by our buildbots.
comment:7 Changed 8 years ago by mkae (Marko Käning)
You are right, indeed I drifted off-topic... Sorry for that.
Best to stick to the pre-commit hook which would have to lint all to-be-committed Portfiles - running thus locally only.
comment:9 Changed 7 years ago by raimue (Rainer Müller)
Summary: | Git: pre-commit-hook could run "port lint" if a Portfile is about to be committed by the user... → Git: pre-commit hook for 'port lint' if a Portfile is about to be committed |
---|
As a start, here is an example pre-commit hook that runs port lint
on all Portfiles in the staged state as they are about to be committed. Put this into macports-ports/.git/hooks/pre-commit
and make it executable with chmod +x
.
#!/bin/bash portdirs=$(git diff --staged --name-only --diff-filter=d | sed '/Portfile$/!d;s/^\(.*\)\/Portfile$/\1/') if [ -n "$portdirs" ]; then git stash push -q --keep-index port lint $portdirs git stash pop -q fi exit 0
This will not reject the commit on warnings or errors, it merely puts out informative messages. Of course this adds a slight delay to the commit process with lots of ports, but port lint
is usually fast and it can also be skipped with git commit --no-verify
.
Should we keep such hooks in the repository? Or should we keep them in the documentation, for example CommitterDocs?
This hook functionality could probably be implemented as a plugin directly on GitHub, so that there wouldn't be the need for inserting this hook on the client's side. (This, however, would only work on PRs then!)