Skip to content

Error when working from within a branch worktree #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
shayded-exe opened this issue Sep 13, 2019 · 13 comments
Open
1 of 4 tasks

Error when working from within a branch worktree #787

shayded-exe opened this issue Sep 13, 2019 · 13 comments

Comments

@shayded-exe
Copy link

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

  • 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
@byCedric
Copy link
Member

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/<submodule?/COMMIT_EDITMSG"
    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.

@shayded-exe
Copy link
Author

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

@marionebl
Copy link
Contributor

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?

@Zelnox
Copy link

Zelnox commented Oct 23, 2019

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.

@byCedric
Copy link
Member

byCedric commented Oct 24, 2019

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 added a commit to syndesisio/syndesis that referenced this issue Oct 25, 2019
The 8.2 version of commitlint has issues working with git worktrees.

This upgrades to 8.3.3 which doesn't manifest these.

Ref conventional-changelog/commitlint#787
@byCedric
Copy link
Member

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

@zregvart
Copy link

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

@MrStLouis
Copy link

MrStLouis commented Mar 27, 2020

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

@BleedingDev
Copy link

Is this problem being worked on? Blocks our workflow. :(

@escapedcat
Copy link
Member

@pegak nope, it's labeled with help wanted though ;)

@BleedingDev
Copy link

I will try to find time as it blocks the colleague work flow and I am more focused on platform. :)

@thisjt
Copy link

thisjt commented Jun 9, 2024

For those encountering the issue with

[info] file:///C:/Users/[redacted]/pnpm-cache/dlx/[redacted]/node_modules/.pnpm/
@[email protected]_@[email protected][email protected]/node_modules/@commitlint/cli/lib/cli.js:127
        throw err;
        ^

Error: ENOENT: no such file or directory, open 'D:\thisjt-projects\svelte-test\$1'

A dirty workaround for this is to manually specify where the COMMIT_EDITMSG lives in the .husky/commit-msg file.

# pnpx commitlint --edit D:/thisjt-projects/svelte-main/.git/worktrees/svelte-test/COMMIT_EDITMSG
pnpx commitlint --edit $GIT_DIR/COMMIT_EDITMSG

I have my main work branch inside svelte-main and I have a worktree in svelte-test. I can't be bothered to make a better workaround for now.

@raind33
Copy link

raind33 commented Jul 25, 2024

I have an issue:

/Users/xxx/Desktop/work/oss.worktrees/release/node_modules/@commitlint/cli/lib/cli.js:123
throw err;
^

[Error: ENOENT: no such file or directory, open '/Users/xxx/Desktop/work/oss/.git/worktrees/release/COMMIT_EDITMSG'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/xxx/Desktop/work/oss/.git/worktrees/release/COMMIT_EDITMSG'
}

I want to know what I should do to solve the issue

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

No branches or pull requests

10 participants