Skip to content

fix: Git submodule file priority on commit message edit #4038

Open
@erayaydin

Description

@erayaydin

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

  • 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/cli@19.2.2

git --version

git version 2.44.0

node --version

v21.7.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @escapedcat@erayaydin

        Issue actions

          fix: Git submodule file priority on commit message edit · Issue #4038 · conventional-changelog/commitlint