Skip to content

Commit

Permalink
feat: add debug logs, set process.env.GK_LOCK_DEBUG =1 to enable
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Jul 19, 2018
1 parent 7fc6069 commit b30f525
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/git-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `[email protected]:${info.repoSlug}`
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit b30f525

Please sign in to comment.