Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add debug logs, set process.env.GK_LOCK_DEBUG =1 to enable #190

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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