Skip to content

Instantly share code, notes, and snippets.

@doesdev
Last active January 21, 2019 17:45
Show Gist options
  • Save doesdev/37ec73ff8aaf9763e0dffdaf1dc7b6d7 to your computer and use it in GitHub Desktop.
Save doesdev/37ec73ff8aaf9763e0dffdaf1dc7b6d7 to your computer and use it in GitHub Desktop.
Find files changed in git commits with message matching a pattern
'use strict'
const repo = require('simple-git')(__dirname)
const rgx = /this|that/i
const start = (new Date('2014-12-29 00:00:00 -0500')).valueOf()
const sinceStart = (c) => (new Date(c.date)).valueOf() > start
const fileMap = {}
repo.log([], async (err, d) => {
const commits = d.all.filter((c) => c.message.match(rgx) && sinceStart(c))
await Promise.all(commits.map((c) => new Promise((resolve, reject) => {
const cmd = ['diff-tree', '--no-commit-id', '--name-only', '-r', c.hash]
repo.raw(cmd, (err, result) => {
if (err) reject(err)
result.split('\n').forEach((f) => { if (f) fileMap[f] = true })
resolve()
})
})))
const map = ([k, v]) => `- ${k}\n ${v.reverse().map((vv) => `${vv}`).join(`\n `)}`
const toPrint = Object.entries(fileMap).map(map).sort().join('\n\n')
console.log(toPrint)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment