Skip to content

Commit

Permalink
feat: add support for git amend (#126)
Browse files Browse the repository at this point in the history
* feat: add support for git amend

So as to allow users to maintain there "one commit" [style][eslint],
this PR adds the ability to specify whether or not to have the lockfile
update be amended into the previous commit.

[eslint]: https://eslint.org/docs/1.0.0/developer-guide/contributing#step-5-squash-your-commits

* test: remove duplicates
  • Loading branch information
James Whitney authored and hulkoba committed Mar 13, 2018
1 parent c1b8169 commit 3749a63
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1,858 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage
node_modules
*.log
# jest coverage output
Expand Down
15 changes: 11 additions & 4 deletions lib/update-lockfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const exec = require('child_process').execSync

const _ = require('lodash')
const semver = require('semver')

const flags = {
Expand Down Expand Up @@ -47,15 +47,22 @@ module.exports = function updateLockfile (dependency, options) {

const commitEmail = process.env.GK_LOCK_COMMIT_EMAIL ? process.env.GK_LOCK_COMMIT_EMAIL.trim() : 'support@greenkeeper.io'
const commitName = process.env.GK_LOCK_COMMIT_NAME ? process.env.GK_LOCK_COMMIT_NAME.trim() : 'greenkeeperio-bot'
const shouldAmend = !_.includes([undefined, `0`, 'false', 'null', 'undefined'], process.env.GK_LOCK_COMMIT_AMEND)

if (exec('git status --porcelain').toString() === '') return

// commit the updated lockfile
// stage the updated lockfile
exec('git add npm-shrinkwrap.json 2>/dev/null || true')
exec('git add package-lock.json 2>/dev/null || true')
exec('git add yarn.lock 2>/dev/null || true')

exec(`git config user.email "${commitEmail}"`)
exec(`git config user.name "${commitName}"`)
const updateMessage = 'chore(package): update lockfile\n\nhttps://npm.im/greenkeeper-lockfile'
exec(`git commit -m "${updateMessage}"`)

if (shouldAmend) {
exec(`git commit --amend --author="${commitName} <${commitEmail}>" --no-edit`)
} else {
const updateMessage = 'chore(package): update lockfile\n\nhttps://npm.im/greenkeeper-lockfile'
exec(`git commit -m "${updateMessage}"`)
}
}
Loading

0 comments on commit 3749a63

Please sign in to comment.