commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

fix: Git submodule file priority on commit message edit

Open erayaydin opened this issue 2 years ago • 0 comments

Steps to Reproduce

  1. Create example folder structure
.
├── Folder1 (submodule)
│   ├── .git (file)
│   │   ...
│   ├── Project1
│   │   ├── .git (folder)
│   │   │   ├── COMMIT_EDITMSG
│   │   ...
  1. Install commitlint with commitizen integration
  2. Run yarn cm (see Extra section)

Extra

.husky/commit-msg

#!/bin/sh
npx --no -- commitlint --edit $1

commitlint.config.ts

import type { UserConfig } from '@commitlint/types';

const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', ['feat', 'fix']],
  },
};

export default Configuration;

.czrc

{
  "path": "@commitlint/cz-commitlint"
}

package.json

{
  ...
  "scripts": {
    ...
    "cm": "cz",
    ...
  },
  ...
}

Current Behavior

Trying to use submodule instead of project git repository

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

Error: ENOTDIR: not a directory, open '/***/Folder1/.git/COMMIT_EDITMSG'
    at async open (node:internal/fs/promises:637:25)
    at async Object.readFile (node:internal/fs/promises:1246:14)
    at async getEditCommit (file:///***/Project1/nextjs-boilerplate/node_modules/@commitlint/read/lib/get-edit-commit.js:13:22)
    at async main (file:///***/Project1/nextjs-boilerplate/node_modules/@commitlint/cli/lib/cli.js:174:19) {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'open',
  path: '/***/Folder1/.git/COMMIT_EDITMSG'
}

Expected Behavior

Use Project1's git folder instead of Folder1 git file.

Affected packages

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

Possible Solution

Add option to searchDotGit function to pass these options to the findUp. This way, we can exclude files and select only directories.

https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/top-level/src/index.ts#L23-L24

commitlint --version

@commitlint/[email protected]

git --version

git version 2.44.0

node --version

v21.7.3

erayaydin avatar Apr 22 '24 09:04 erayaydin