From 5d74b1ff330fe76ee12b5915f10fcca3a0ed8383 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Thu, 19 Jul 2018 17:29:31 +0200 Subject: [PATCH] feat: add debug logs, set process.env.GK_LOCK_DEBUG =1 to enable --- lib/git-helpers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/git-helpers.js b/lib/git-helpers.js index 60c0f624..619ff48a 100644 --- a/lib/git-helpers.js +++ b/lib/git-helpers.js @@ -4,6 +4,7 @@ const url = require('url') const exec = require('child_process').execSync const _ = require('lodash') +const DEBUG = process.env.GK_LOCK_DEBUG || false module.exports = { getNumberOfCommitsOnBranch: function getNumberOfCommitsOnBranch (branch) { @@ -42,28 +43,35 @@ module.exports = { exec(`git stash`) exec(`git checkout ${defaultBranch}`) + DEBUG && console.log('sucessfully funged the git repo, so we can diff this branch against the default branch') + const reset = () => exec(`git checkout -`) try { const gitShowCmd = `git show --oneline --name-only origin/${info.branchName}...${defaultBranch}` const grepCmd = `grep -E '(package-lock.json|npm-shrinkwrap.json|yarn.lock)'` + DEBUG && console.log(`about to run ${gitShowCmd} | ${grepCmd}`) exec(`${gitShowCmd} | ${grepCmd}`) } catch (e) { if (e.status === 1 && e.stdout.toString() === '' && e.stderr.toString() === '') { // grep didn’t find anything, and we are fine with that reset() + DEBUG && console.log('grep found no matching commits: ') return false // no commits } else if (e.status > 1) { // git or grep errored reset() + DEBUG && console.log('git or grep errored') throw e } else { - // git succeeded, grep failed to match anything, but no error occured, e.g.: no commit yet + // git succeeded, grep failed to match anything, but no error occured, i,e.: no commit yet + DEBUG && console.log('git succeeded, grep failed to match anything, but no error occured, i.e.: no commit yet') reset() return false } } // git succeeded, grep found a match, we have a commit already + DEBUG && console.log('git succeeded, grep foudn a match, we have a commit already') reset() return true },