1
+ import { sep } from "path" ;
2
+ import * as tempy from "tempy" ;
3
+ import { mkdirp } from "mkdirp" ;
4
+ import { runCommand } from "@softwareventures/precise-commits/lib/utils" ;
1
5
import {
2
6
getDiffForFile ,
3
- resolveNearestGitDirectoryParent ,
7
+ resolveGitWorkingTreePath ,
4
8
getModifiedFilenames ,
5
9
index
6
10
} from "../src/git-utils" ;
@@ -10,7 +14,7 @@ const fixtures = readFixtures();
10
14
let testBed : TestBed ;
11
15
12
16
describe ( "git-utils" , ( ) => {
13
- describe ( "resolveNearestGitDirectoryParent ()" , ( ) => {
17
+ describe ( "resolveGitWorkingTreePath ()" , ( ) => {
14
18
beforeAll ( ( ) => {
15
19
testBed = new TestBed ( ) ;
16
20
} ) ;
@@ -26,11 +30,21 @@ describe("git-utils", () => {
26
30
/**
27
31
* The tmpFile should resolve to its own .git directory
28
32
*/
29
- expect ( await resolveNearestGitDirectoryParent ( tmpFile . directoryPath ) ) . toEqual (
33
+ expect ( await resolveGitWorkingTreePath ( tmpFile . directoryPath ) ) . toEqual (
30
34
tmpFile . directoryPath
31
35
) ;
32
36
} ) ;
33
37
} ) ;
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
+ await runCommand ( "git" , [ "worktree" , "add" , "-B" , "worktree" , worktreePath ] ) ;
42
+ const subdirPath = `${ worktreePath } ${ sep } subdir` ;
43
+ await mkdirp ( subdirPath ) ;
44
+ expect ( await resolveGitWorkingTreePath ( subdirPath ) ) . toEqual ( worktreePath ) ;
45
+ await runCommand ( "git" , [ "worktree" , "remove" , worktreePath ] ) ;
46
+ } ) ;
47
+ } ) ;
34
48
} ) ;
35
49
36
50
describe ( "getDiffForFile()" , ( ) => {
@@ -46,9 +60,7 @@ describe("git-utils", () => {
46
60
it ( fixture . fixtureName , async ( ) => {
47
61
await testBed . prepareFixtureInTmpDirectory ( fixture ) ;
48
62
const tmpFile = testBed . getTmpFileForFixture ( fixture ) ;
49
- const gitDirectoryParent = await resolveNearestGitDirectoryParent (
50
- tmpFile . directoryPath
51
- ) ;
63
+ const gitDirectoryParent = await resolveGitWorkingTreePath ( tmpFile . directoryPath ) ;
52
64
const diff = await getDiffForFile (
53
65
gitDirectoryParent ,
54
66
tmpFile . path ,
@@ -73,9 +85,7 @@ describe("git-utils", () => {
73
85
it ( fixture . fixtureName , async ( ) => {
74
86
await testBed . prepareFixtureInTmpDirectory ( fixture ) ;
75
87
const tmpFile = testBed . getTmpFileForFixture ( fixture ) ;
76
- const gitDirectoryParent = await resolveNearestGitDirectoryParent (
77
- tmpFile . directoryPath
78
- ) ;
88
+ const gitDirectoryParent = await resolveGitWorkingTreePath ( tmpFile . directoryPath ) ;
79
89
const fileNames = await getModifiedFilenames (
80
90
gitDirectoryParent ,
81
91
tmpFile . initialCommitSHA ,
0 commit comments