conventional-changelog / commitlint

đź““ Lint commit messages
https://commitlint.js.org
MIT License
16.93k stars 912 forks source link

fatal: ambiguous argument 'HEAD1..HEAD' error on Windows #4106

Open matyasf opened 4 months ago

matyasf commented 4 months ago

Steps to Reproduce

We are running the following command: commitlint --from=HEAD^1. This works fine on OSX, but fails in Windows 10 (cmd.exe) with the following error:

/node_modules/@commitlint/cli/lib/cli.js:127
        throw err;
        ^

Error: fatal: ambiguous argument 'HEAD1..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at Transform.transform [as _transform] (C:\CODE\instructure-ui\node_modules\git-raw-commits\index.js:100:36)
    at Transform._write (node:internal/streams/transform:171:8)
    at writeOrBuffer (node:internal/streams/writable:570:12)
    at _write (node:internal/streams/writable:499:10)
    at Writable.write (node:internal/streams/writable:508:10)
    at Socket.ondata (node:internal/streams/readable:1007:22)
    at Socket.emit (node:events:532:35)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)

Node version: 22

commitlint.config.js:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  parserOpts: {
    headerPattern: /^(\w*)\((\w*)\)-(\w*)\s(.*)$/,
    headerCorrespondence: ['type', 'scope', 'subject']
  },
  // see https://commitlint.js.org/#/reference-rules
  rules: {
    'type-enum': [
      2,
      'always',
      [
        'WIP',
        'feat',
        'fix',
        'docs',
        'chore',
        'style',
        'refactor',
        'test',
        'perf',
        'revert'
      ]
    ],
    'type-case': [0],
    'header-max-length': [0, 'always', 150] // commit message first field (subject) length
  }
}

versions:

"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",

(was producing the same error on v17)

running via Husky



### Current Behavior

crash

### Expected Behavior

no crash

### Affected packages

- [X] cli
- [ ] core
- [ ] prompt
- [ ] config-angular

### Possible Solution

_No response_

### Context

_No response_

### commitlint --version

19.3.0

### git --version

2.45.2.windows.1

### node --version

v22.5.1
escapedcat commented 4 months ago

Does this duplicate or relate to https://github.com/conventional-changelog/commitlint/issues/6?

knocte commented 2 months ago

We are running the following command: commitlint --from=HEAD^1

What does HEAD^1 mean? is it the same as HEAD~1? And why are you not using --to?

Leinark commented 2 months ago

I have the same error in GitHub Actions. I use runs-on: ubuntu-latest and install the packages: cli, config-conventional, and types. The command I run is: pnpm dlx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

knocte commented 2 months ago

@MatthieuLeterme you are using ~ but the reporter of this bug used ^, please open a new bug.