@@ -12,12 +12,14 @@ function changeGitDir(newDirName) {
12
12
13
13
function findRepoHandleLinkedWorktree ( gitPath ) {
14
14
var stat = fs . statSync ( gitPath ) ;
15
+ var root = path . dirname ( path . resolve ( gitPath ) ) ;
15
16
if ( stat . isDirectory ( ) ) {
16
17
return {
17
18
// for the base (non-linked) dir, there is no distinction between where we
18
19
// find the HEAD file and where we find the rest of .git
19
20
worktreeGitDir : gitPath ,
20
21
commonGitDir : gitPath ,
22
+ root : root ,
21
23
} ;
22
24
} else {
23
25
// We have a file that tells us where to find the worktree git dir. Once we
@@ -30,21 +32,22 @@ function findRepoHandleLinkedWorktree(gitPath) {
30
32
var worktreeGitDir = path . resolve ( absolutePath , worktreeGitDirUnresolved ) ;
31
33
var commonDirPath = path . join ( worktreeGitDir , 'commondir' ) ;
32
34
if ( fs . existsSync ( commonDirPath ) ) {
33
- // this directory contains a `commondir` file; we're within a linked
34
- // worktree
35
+ // this directory contains a `commondir` file; we're in a linked worktree
35
36
36
37
var commonDirRelative = fs . readFileSync ( commonDirPath ) . toString ( ) . replace ( / \r ? \n $ / , '' ) ;
37
38
var commonDir = path . resolve ( path . join ( worktreeGitDir , commonDirRelative ) ) ;
38
39
39
40
return {
40
41
worktreeGitDir : worktreeGitDir ,
41
42
commonGitDir : commonDir ,
43
+ root : path . dirname ( commonDir ) ,
42
44
} ;
43
45
} else {
44
46
// there is no `commondir` file; we're in a submodule
45
47
return {
46
48
worktreeGitDir : worktreeGitDir ,
47
49
commonGitDir : worktreeGitDir ,
50
+ root : root ,
48
51
} ;
49
52
}
50
53
}
@@ -94,7 +97,7 @@ function getPackedRefsFile(gitPath) {
94
97
}
95
98
96
99
function getLinesForRefPath ( packedRefsFile , type , refPath ) {
97
- return packedRefsFile . split ( '\n' ) . reduce ( function ( acc , line , idx , arr ) {
100
+ return packedRefsFile . split ( / \r ? \n / ) . reduce ( function ( acc , line , idx , arr ) {
98
101
var targetLine = line . indexOf ( '^' ) > - 1 ? arr [ idx - 1 ] : line ;
99
102
return doesLineMatchRefPath ( type , line , refPath ) ? acc . concat ( targetLine ) : acc ;
100
103
} , [ ] ) ;
@@ -132,7 +135,7 @@ function commitForTag(gitPath, tag) {
132
135
// 'tag 172\u0000object c1ee41c325d54f410b133e0018c7a6b1316f6cda\ntype commit\ntag awesome-tag\ntagger Robert Jackson
133
136
// <[email protected] > 1429100021 -0400\n\nI am making an annotated tag.\n'
134
137
if ( objectContents . slice ( 0 , 3 ) === 'tag' ) {
135
- var sections = objectContents . split ( / \0 | \n / ) ;
138
+ var sections = objectContents . split ( / \0 | \r ? \ n/ ) ;
136
139
var sha = sections [ 1 ] . slice ( 7 ) ;
137
140
138
141
return sha ;
@@ -214,16 +217,20 @@ module.exports = function(gitPath) {
214
217
authorDate : null ,
215
218
commitMessage : null ,
216
219
root : null ,
220
+ commonGitDir : null ,
221
+ worktreeGitDir : null ,
217
222
lastTag : null ,
218
223
commitsSinceLastTag : 0 ,
219
224
} ;
220
225
221
226
if ( ! gitPathInfo ) { return result ; }
222
227
223
228
try {
224
- result . root = path . resolve ( gitPathInfo . commonGitDir , '..' ) ;
229
+ result . root = gitPathInfo . root ;
230
+ result . commonGitDir = gitPathInfo . commonGitDir ;
231
+ result . worktreeGitDir = gitPathInfo . worktreeGitDir ;
225
232
226
- var headFilePath = path . join ( gitPathInfo . worktreeGitDir , 'HEAD' ) ;
233
+ var headFilePath = path . join ( gitPathInfo . worktreeGitDir , 'HEAD' ) ;
227
234
228
235
if ( fs . existsSync ( headFilePath ) ) {
229
236
var headFile = fs . readFileSync ( headFilePath , { encoding : 'utf8' } ) ;
@@ -290,7 +297,7 @@ function getCommitData(gitPath, sha) {
290
297
if ( zlib . inflateSync && fs . existsSync ( objectPath ) ) {
291
298
var objectContents = zlib . inflateSync ( fs . readFileSync ( objectPath ) ) . toString ( ) ;
292
299
293
- return objectContents . split ( / \0 | \n / )
300
+ return objectContents . split ( / \0 | \r ? \ n/ )
294
301
. filter ( function ( item ) {
295
302
return ! ! item ;
296
303
} )
@@ -315,7 +322,7 @@ function getCommitData(gitPath, sha) {
315
322
}
316
323
break ;
317
324
case 'parent' :
318
- data . parents = section . split ( '\n' ) . map ( p => p . split ( ' ' ) [ 1 ] ) ;
325
+ data . parents = section . split ( / \r ? \n / ) . map ( p => p . split ( ' ' ) [ 1 ] ) ;
319
326
break ;
320
327
default :
321
328
//should just be the commit message left
0 commit comments