Estoy tratando de determinar si mi process de nodo se está ejecutando en un directory git. Lo siguiente funciona, pero aún muestra un error fatal en la console.
function testForGit() { try { var test = execSync('git rev-parse --is-inside-work-tree', {encoding: 'utf8'}); } catch (e) { } return !!test; } console.log(testForGit());
Cuando estoy en un directory bajo el control de git, me hago true
como resultado. Pero cuando estoy fuera de un directory bajo el control de git, obtengo:
fatal: Not a git repository (or any of the parent directories): .git false
Mis preguntas):
¿Hay alguna manera de suprimir el error que se registra? ¿O hay una forma mejor de determinar si estoy en un directory bajo control git?
Esencialmente, estoy tratando de hacer el equivalente bash de
if git rev-parse --git-dir > /dev/null 2>&1; then ... do something fi
Puede tratar de networkingirigir stdout
dentro de la llamada execSync
, así:
var test = execSync('git rev-parse --is-inside-work-tree 2>/dev/null', {encoding: 'utf8'});