1- import { TestBed , readFixtures } from "./test-utils" ;
1+ import { sep } from "path" ;
2+ import * as tempy from "tempy" ;
3+ import { mkdirp } from "mkdirp" ;
4+ import { runCommandSync } from "../src/utils" ;
25import {
36 getDiffForFile ,
4- resolveNearestGitDirectoryParent ,
7+ resolveGitWorkingTreePath ,
58 getModifiedFilenames ,
69 index
710} from "../src/git-utils" ;
11+ import { TestBed , readFixtures } from "./test-utils" ;
812
913const fixtures = readFixtures ( ) ;
1014let testBed : TestBed ;
1115
1216describe ( "git-utils" , ( ) => {
13- describe ( "resolveNearestGitDirectoryParent ()" , ( ) => {
17+ describe ( "resolveGitWorkingTreePath ()" , ( ) => {
1418 beforeAll ( ( ) => {
1519 testBed = new TestBed ( ) ;
1620 } ) ;
@@ -26,11 +30,21 @@ describe("git-utils", () => {
2630 /**
2731 * The tmpFile should resolve to its own .git directory
2832 */
29- expect ( resolveNearestGitDirectoryParent ( tmpFile . directoryPath ) ) . toEqual (
33+ expect ( resolveGitWorkingTreePath ( tmpFile . directoryPath ) ) . toEqual (
3034 tmpFile . directoryPath
3135 ) ;
3236 } ) ;
3337 } ) ;
38+
39+ it ( `should resolve the correct working tree path in a working tree created by git worktree` , async ( ) => {
40+ await tempy . directory . task ( async worktreePath => {
41+ runCommandSync ( "git" , [ "worktree" , "add" , "-B" , "worktree" , worktreePath ] ) ;
42+ const subdirPath = `${ worktreePath } ${ sep } subdir` ;
43+ await mkdirp ( subdirPath ) ;
44+ expect ( resolveGitWorkingTreePath ( subdirPath ) ) . toEqual ( worktreePath ) ;
45+ runCommandSync ( "git" , [ "worktree" , "remove" , worktreePath ] ) ;
46+ } ) ;
47+ } ) ;
3448 } ) ;
3549
3650 describe ( "getDiffForFile()" , ( ) => {
@@ -46,8 +60,9 @@ describe("git-utils", () => {
4660 it ( fixture . fixtureName , ( ) => {
4761 testBed . prepareFixtureInTmpDirectory ( fixture ) ;
4862 const tmpFile = testBed . getTmpFileForFixture ( fixture ) ;
63+ const gitDirectoryParent = resolveGitWorkingTreePath ( tmpFile . directoryPath ) ;
4964 const diff = getDiffForFile (
50- resolveNearestGitDirectoryParent ( tmpFile . directoryPath ) ,
65+ gitDirectoryParent ,
5166 tmpFile . path ,
5267 tmpFile . initialCommitSHA ,
5368 tmpFile . updatedCommitSHA ?? index
@@ -70,8 +85,9 @@ describe("git-utils", () => {
7085 it ( fixture . fixtureName , ( ) => {
7186 testBed . prepareFixtureInTmpDirectory ( fixture ) ;
7287 const tmpFile = testBed . getTmpFileForFixture ( fixture ) ;
88+ const gitDirectoryParent = resolveGitWorkingTreePath ( tmpFile . directoryPath ) ;
7389 const fileNames = getModifiedFilenames (
74- resolveNearestGitDirectoryParent ( tmpFile . directoryPath ) ,
90+ gitDirectoryParent ,
7591 tmpFile . initialCommitSHA ,
7692 tmpFile . updatedCommitSHA
7793 ) ;
0 commit comments