diff --git a/lib/command-requirements.js b/lib/command-requirements.js index e22f78c..bd1ed37 100644 --- a/lib/command-requirements.js +++ b/lib/command-requirements.js @@ -1,27 +1,24 @@ var fs = require('fs'), - path = require('path'); + path = require('path'), + exec = require('child_process').exec; module.exports = { git: function(req) { - var stat; try { - stat = fs.statSync(req.path + '/.git/'); - if (stat.isDirectory()) { - return true; - } - } catch (e) { - // check if the directory is a submodule - // addresses https://github.com/mixu/gr/issues/54 - if (e.code === 'ENOTDIR' || e.code === 'ENOENT') { - var parentPath = path.dirname(req.path); - try { - stat = fs.statSync(parentPath + '/.gitmodules'); - if (stat.isFile()) { - return true; - } - } catch (e) { } - } - } + exec('git rev-parse --show-prefix', { + cwd: req.path, + }, function(err, stdout, stderr) { + stdout = stdout.replace(/(\r\n|\n|\r)/gm,'').trim() + if(err !== null) { + console.log('*** Not a Git repository, should return false\n>>> req.path: "' + req.path + '"\n>>> err: ' + err + '\n>>> stdout: "' + stdout + '"\n>>> stderr: "' + stderr + '"'); + } + if(stdout) { + console.log('*** Not in repository/submodule root dir, should return false\n>>> req.path: "' + req.path + '"\n>>> err: ' + err + '\n>>> stdout: "' + stdout + '"\n>>> stderr: "' + stderr + '"'); + } + console.log('*** OK, return true or do nothing\n>>> req.path: "' + req.path + '"\n>>> err: ' + err + '\n>>> stdout: "' + stdout + '"\n>>> stderr: "' + stderr + '"'); + }); + return true; + } catch (e) { } if (req.format === 'human') { console.log('Skipped ' + req.path + ' as it does not have a .git subdirectory and is not a submodule.'); }