File tree 1 file changed +8
-17
lines changed
1 file changed +8
-17
lines changed Original file line number Diff line number Diff line change 1
1
var path = require ( 'path' ) ;
2
2
var util = require ( 'util' ) ;
3
3
var spawn = require ( 'child_process' ) . spawn ;
4
+ var execSync = require ( 'child_process' ) . execSync ;
4
5
var fs = require ( 'fs' ) ;
5
6
var fsHelpers = require ( './fs-helpers' ) ;
6
7
@@ -165,27 +166,17 @@ function spawnHook(hookName, args) {
165
166
}
166
167
167
168
/**
168
- * Returns the closest git directory.
169
- * It starts looking from the current directory and does it up to the fs root.
170
- * It returns undefined in case where the specified directory isn't found.
169
+ * Runs git rev-parse to find the git directory of the currentPath.
171
170
*
172
171
* @param {String } [currentPath] Current started path to search.
173
172
* @returns {String|undefined }
174
173
*/
175
174
function getClosestGitPath ( currentPath ) {
176
- currentPath = currentPath || process . cwd ( ) ;
177
-
178
- var dirnamePath = path . join ( currentPath , '.git' ) ;
179
-
180
- if ( fsHelpers . exists ( dirnamePath ) ) {
181
- return dirnamePath ;
182
- }
183
-
184
- var nextPath = path . resolve ( currentPath , '..' ) ;
185
-
186
- if ( nextPath === currentPath ) {
187
- return ;
175
+ try {
176
+ var result = execSync ( 'git rev-parse --git-dir' , { cwd : currentPath } ) . toString ( ) ;
177
+ return result . replace ( / \n / g, '' ) ;
178
+ } catch ( error ) {
179
+ // No git dir?
180
+ return undefined ;
188
181
}
189
-
190
- return getClosestGitPath ( nextPath ) ;
191
182
}
You can’t perform that action at this time.
0 commit comments