diff --git a/lib/git-helpers.js b/lib/git-helpers.js index a6caf36f..a2fb34b4 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 function setupRemote (info) { let remote = `git@github.com:${info.repoSlug}` @@ -56,28 +57,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 },