-
-
Notifications
You must be signed in to change notification settings - Fork 453
fix: fix the incorrect relativeTopLevelDir detection when working with the worktree #1608
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
Conversation
…en when the folder is worktree
🦋 Changeset detectedLatest commit: 5100cac The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thanks for the PR! The fix makes sense, but would you be willing to add a test for it so that it doesn't break in the same way in the future? |
Thanks for the suggestion! In this particular case, adding an automated test would be impractical — the scenario is very specific and would require an extensive amount of mocking to reproduce. That would end up testing the mocks rather than the actual behavior, and it’s likely to be fragile and prone to flakiness. I think in this case it’s safer to rely on code review and manual verification for this edge case. |
@srsatt is that an AI reply? 👀 This repo has a lot of integration tests that run in isolated environments without needing any mocking, pretty easy to run lint-staged by supplying the |
@iiroj I'll try to write a test, but just to make sure: you refered to |
@skoch13 yes, oops, you are correct. |
I can also release this as a patch without the test if you promise to contribute one separately, given that all the existing tests pass as-is. 👍 |
@iiroj I'm failing to reproduce the behavior I described, however my test still green test.only(
'handles monorepo git worktrees',
withGitIntegration(async ({ appendFile, cwd, execGit, gitCommit, readFile }) => {
const processEnvBackup = process.env.GIT_DIR
// creating a separate worktree outside of main worktree directory
const workTreeDir = await createTempDir()
const workTreeModuleDir = path.resolve(workTreeDir, 'frontend')
await execGit(['worktree', 'add', '-b', 'test', workTreeDir])
await appendFile('.lintstagedrc.json', JSON.stringify(prettierListDifferent), workTreeDir)
process.chdir(workTreeDir)
await appendFile('test.js', fileFixtures.prettyJS, workTreeModuleDir)
await execGit(['add', 'test.js'], { cwd: workTreeModuleDir })
process.env.GIT_DIR = path.resolve(cwd, '.git', 'worktrees', path.basename(workTreeDir))
await gitCommit({ lintStaged: { debug: true } }, workTreeModuleDir)
// Nothing is wrong, so a new commit is created
expect(await execGit(['rev-list', '--count', 'HEAD'], { cwd: workTreeDir })).toEqual('2')
expect(await execGit(['log', '-1', '--pretty=%B'], { cwd: workTreeDir })).toMatch('test')
expect(await readFile('test.js', workTreeModuleDir)).toEqual(fileFixtures.prettyJS)
process.env.GIT_DIR = processEnvBackup
})
) ![]() |
@skoch13 now that I take fresh look, I think for integration tests one can't directly pass environment variables. Maybe setting the Unfortunately, I don' use this kind of setups myself so not that familiar with it. |
fixes #1607