Commitlint: Error when working from within a branch worktree

Created on 14 Sep 2019  路  8Comments  路  Source: conventional-changelog/commitlint


When trying to run commitlint from within a branch worktree directory, I get the following error: could not find git root from undefined

Expected Behavior



The operation should succeed without error.

Current Behavior



The operation errors with could not find git root from undefined

Affected packages

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

Steps to Reproduce (for bugs)


  1. Checkout a repo
  2. Checkout a different branch into a separate folder via worktree: git worktree add -b my-branch ../my-branch
  3. CD into the branch folder
  4. Make some changers
  5. Try to commit

Your Environment

| Executable | Version |
| ---: | :--- |
| commitlint --version | 8.1.0 |
| git --version | git version 2.20.1.windows.1 |
| node --version | v10.14.1 |

bug help wanted

All 8 comments

Hi @PachowStudios! Thanks for the report, does your use case match this issue?

Hi, @byCedric
Thanks for your response.

Here is more detail want to share with you.

  1. About your suggestion commitlint --edit=".git/modules/ This one definitely can work but it is not suite for our situation. In our super repo, > there are 30+ submodules, and still growing. So we do not want to add so many duplicated scripts in the package.json file.

  2. With the git submodule workflow. We need figure out 2 concepts. one is the super-repo(parent), another is the sub-repo(child). The only connection between them is a commit-id(or a hash-id), but still, they are 2 independent repo.
    So if we run git cm -m "test" in the super-repo folder, the commit message will be written into the superFolder/.git/COMMIT_EDITMSG file and the commit will get into the super-repo;
    and if we run git cm -m "test" in the sub-repo folder, the commit message will be written into the superFolder/.git/modules/subRepoName/COMMIT_EDITMSG file and the commit will get into the sub-repo.
    The real work situation for us is: If we had some changes for a sub repo, we will get inside the subFolder, do the modification > git cm > git push, just like what we did for a normal git repo. The difference is that there is a .git file(NOT a directory) in the subFolder, and inside this .git file contains the real git directory location: gitdir: ../.git/modules/subRepoName.

One more thing: we can downgrade the commitlint to "7.6.1" and it worked for our situation. But still, do hope you can fix this and publish a new version to the npm registry.

Thank you.

@byCedric not quite. I'm not using submodules, I'm using worktrees.

Thanks for reporting, this is the first time I heard of git worktrees.

commitlint logic to find the git root folder (and relevant .git database) does not support worktrees as it stands. I suggest we treat this as a bug.

A possible fix for this would be to replace our custom implementation with a call to git rev-parse --show-toplevel. Want to lend a hand?

I've been using commitlint with worktrees for several months now without any issue. I started to see this problem this week.

Executable | Version
-- | --
commitlint --version | 8.2.0
git --version | git version 2.23.0
node --version | v10.16.3

Update: We updated commitlint to 8.2 from 7.6.1 a few days ago. I've downgraded to test: it works with worktrees on 7.6.1.

Hi @Zelnox, thanks for your info! 鉂わ笍 I believe the issue is related to some refactoring we did to port to TypeScript. We had to update a library, which "behaves" a bit different now.

That being said, we already fixed _some_ of these issues. We also have a new version in testing right now, and it includes some rewrites that we had to do to support a new commit parser. You can try if version 8.3.3 of commitlint works better with your use case, that's the one in npm with the label next.

You can install this version with:

$ npm i --save @commitlint/cli@next (or commitlint@next)

It would definitely help us determine a proper fix if you could test this one. 馃槃

@zregvart Thanks for checking! 馃槃 The issues you mentioned with Commitlint appears to be fixed with v8.3.3, right?

@byCedric, well, works on my machine :smile: 8.2 had the issue, 8.3 doesn't. Thank you for fixing it.

I seem to be having an issue with commitlint and worktrees but not this exact one (happy to create another issue if needed)

Executable | Version
-- | --
commitlint --version | 8.3.5
git --version | 2.25.0.windows.1
node --version | 12.16.1

I have my main worktree under develop and two linked trees for active features
committing from develop works fine, committing from one of the features does not. I get

C:\Users\ME\Documents\_Clients\My Project\Custom\lfc-tools\feature\rcfiles\node_modules\@commitlint\cli\lib\cli.js:124
        throw err;
        ^

[Error: ENOENT: no such file or directory, open 'C:\Users\ME\Documents\_Clients\My'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
}

note the full path of the module is my project directory. the no such file error is being cut off before the space in my project path. Going to try removing the space in my directory, but some program has it locked.

ok I will try cloning into a different folder. renaming a parent directory screwed up so many things in git

Was this page helpful?
0 / 5 - 0 ratings