Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e3ce22

Browse files
srsattPavel Reutoviiroj
authored
fix: fix the incorrect relativeTopLevelDir detection when working with the worktree (#1608)
* fix: fix the incorrect relativeTopLevelDir detection for the cases when when the folder is worktree * docs: create ten-bears-battle.md --------- Co-authored-by: Pavel Reutov <[email protected]> Co-authored-by: Iiro Jäppinen <[email protected]>
1 parent 9151254 commit 4e3ce22

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lint-staged": patch
3+
---
4+
5+
Detect the git repo's top-level directory correctly when in a worktree.

‎lib/resolveGitRepo.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ export const resolveGitRepo = async (cwd = process.cwd()) => {
3939
try {
4040
debugLog('Resolving git repo from `%s`', cwd)
4141

42-
/** Git rev-parse returns all three flag values on separate lines */
43-
const revParseOutput = await execGit(['rev-parse', CDUP, TOPLEVEL, ABSOLUTE_GIT_DIR], {
44-
cwd,
45-
})
46-
const [relativeTopLevelDir, topLevel, absoluteGitDir] = revParseOutput.split('\n')
47-
4842
// Unset GIT_DIR before running any git operations in case it's pointing to an incorrect location
4943
debugLog('Unset GIT_DIR (was `%s`)', process.env.GIT_DIR)
5044
delete process.env.GIT_DIR
5145
debugLog('Unset GIT_WORK_TREE (was `%s`)', process.env.GIT_WORK_TREE)
5246
delete process.env.GIT_WORK_TREE
5347

48+
/** Git rev-parse returns all three flag values on separate lines */
49+
const revParseOutput = await execGit(['rev-parse', CDUP, TOPLEVEL, ABSOLUTE_GIT_DIR], {
50+
cwd,
51+
})
52+
const [relativeTopLevelDir, topLevel, absoluteGitDir] = revParseOutput.split('\n')
53+
5454
const topLevelDir = normalizePath(path.join(cwd, relativeTopLevelDir))
5555
debugLog('Resolved git repository top-level directory to be `%s`', topLevelDir)
5656

0 commit comments

Comments
 (0)