Commitlint: Improvement(/Bug): Missing shebang causes problems for cli when used with pre-commit

Created on 31 Oct 2020  路  8Comments  路  Source: conventional-changelog/commitlint

Expected Behavior

pre-commit is a git hook framework which also supports commit-msg hooks. There is a gh-repo which intents to add pre-commit support to commitlint.

After adding this to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
    rev: a330c424e7903ebbe62b57154456d80d5fbc2b11  # frozen: v4.0.0
    hooks:
      - id: commitlint
        stages: [commit-msg]
        additional_dependencies: ['@commitlint/config-angular']

and installing the hook

$ pre-commit install -t commit-msg

it should run on every commit and abort the commit if commitlint does not give its ok.

Current Behavior

Currently I get an error:

$ git commit -m "test commit"
commitlint...............................................................Failed
- hook id: commitlint
- exit code: 1

[Errno 8] Exec format error: '/home/krys/.cache/pre-commit/repowovky9t0/node_env-system/bin/commitlint'

*** Exit Code: 1 ***

After some googlin' I found out that a missing shebang could be the cause. And indeed the mentioned file does not have one, starting with:

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
...


Affected packages

  • [x] cli
  • [ ] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

The aforementioned repo also supports commitlint-travis as a hook. After looking into the commitlint-travis file in the bin directory mentioned in the error I found a shebang: #!/usr/bin/env node.
As I don't have any knowledge on node or JS/TS I could not backtrack those files into the source code as the files seem to differ from the installed ones.

Would it be possible to add a shebang to the corresponding file for commitlint-cli as it is for commitlint-travis?

Steps to Reproduce (for bugs)

  1. You need to have python installed
  2. Install pre-commit: curl https://pre-commit.com/install-local.py | python -
  3. create a git repo
  4. create a .pre-commit-config.yaml file with the content from above
  5. install hook locally pre-commiit install -t commit-msg
  6. try to commit: git commit -a -m "test"

Context


Your Environment

| Executable | Version |
| ---------------------: | :------ |
| commitlint --version | 11.0.0 |
| git --version | 2.17.1 |
| node --version | v14.15.0 |

OS: linux mint 19.3

Most helpful comment

@ChristianMurphy sorry for tagging you. Tried to tag @Cielquan :P
@Cielquan and @tkcranny thanks for the info.
We'll have a look.

All 8 comments

Hey @ChristianMurphy , thanks for the issue. Would you be willing to provide a PR?

@escapedcat did you mean @Cielquan?

@escapedcat did you mean @Cielquan?

As I wrote the issue I assume @escapedcat means me and not you according to the answer he wrote:

Hey @ChristianMurphy , thanks for the issue. Would you be willing to provide a PR?


@escapedcat I am willing to provide a PR, sure, and adding a shebang should be not the problem, but as mentioned above I don't know which file needs the missing shebang.

As I don't have any knowledge on node or JS/TS I could not backtrack those files into the source code as the files seem to differ from the installed ones.

I assume it's this file because at the same place for the travis one there is this file which has a shebang and both files look somewhat similar to the ones I described from the bin directory of the installed version.

If I am not mistake TypeScript needs to be converted to JavaScript before it can be used or something like this? So the first file is a TS and the second a JS file. Are the shebangs kept while they are converted? If not there is a problem then.

I've run into this myself, and have needed to revert to version 9.1.1 in my company's repo pre-commit hook definition to mitigate this issue.

@ChristianMurphy sorry for tagging you. Tried to tag @Cielquan :P
@Cielquan and @tkcranny thanks for the info.
We'll have a look.

@escapedcat Can you give me an update on this issue? :smile_cat:

No, sorry, hard to find some time at the moment to look into this.

No, sorry, hard to find some time at the moment to look into this.

Ok thanks for letting me know :)

Was this page helpful?
0 / 5 - 0 ratings