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 11var path = require ( 'path' ) ;
22var util = require ( 'util' ) ;
33var spawn = require ( 'child_process' ) . spawn ;
4+ var execSync = require ( 'child_process' ) . execSync ;
45var fs = require ( 'fs' ) ;
56var fsHelpers = require ( './fs-helpers' ) ;
67
@@ -165,27 +166,17 @@ function spawnHook(hookName, args) {
165166}
166167
167168/**
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.
171170 *
172171 * @param {String } [currentPath] Current started path to search.
173172 * @returns {String|undefined }
174173 */
175174function 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 ;
188181 }
189-
190- return getClosestGitPath ( nextPath ) ;
191182}
You can’t perform that action at this time.
0 commit comments