File tree Expand file tree Collapse file tree 1 file changed +8
-17
lines changed Expand file tree Collapse file tree 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
@@ -171,27 +172,17 @@ function spawnHook(hookName, args) {
171
172
}
172
173
173
174
/**
174
- * Returns the closest git directory.
175
- * It starts looking from the current directory and does it up to the fs root.
176
- * It returns undefined in case where the specified directory isn't found.
175
+ * Runs git rev-parse to find the git directory of the currentPath.
177
176
*
178
177
* @param {String } [currentPath] Current started path to search.
179
178
* @returns {String|undefined }
180
179
*/
181
180
function getClosestGitPath ( currentPath ) {
182
- currentPath = currentPath || process . cwd ( ) ;
183
-
184
- var dirnamePath = path . join ( currentPath , '.git' ) ;
185
-
186
- if ( fsHelpers . exists ( dirnamePath ) ) {
187
- return dirnamePath ;
188
- }
189
-
190
- var nextPath = path . resolve ( currentPath , '..' ) ;
191
-
192
- if ( nextPath === currentPath ) {
193
- return ;
181
+ try {
182
+ var result = execSync ( 'git rev-parse --git-dir' , { cwd : currentPath } ) . toString ( ) ;
183
+ return result . replace ( / \n / g, '' ) ;
184
+ } catch ( error ) {
185
+ // No git dir?
186
+ return undefined ;
194
187
}
195
-
196
- return getClosestGitPath ( nextPath ) ;
197
188
}
You can’t perform that action at this time.
0 commit comments