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
@@ -171,27 +172,17 @@ function spawnHook(hookName, args) {
171172}
172173
173174/**
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.
177176 *
178177 * @param {String } [currentPath] Current started path to search.
179178 * @returns {String|undefined }
180179 */
181180function 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 ;
194187 }
195-
196- return getClosestGitPath ( nextPath ) ;
197188}
You can’t perform that action at this time.
0 commit comments