Skip to content

Instantly share code, notes, and snippets.

@simov
Last active December 31, 2017 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simov/a54f20ae73d776a1de96d6e8c6b99aa9 to your computer and use it in GitHub Desktop.
Save simov/a54f20ae73d776a1de96d6e8c6b99aa9 to your computer and use it in GitHub Desktop.
Flat search for changed git repositories: `node check-for-git-changes.js path/to/projects/folder/`
var fs = require('fs')
var path = require('path')
var cp = require('child_process')
if (!process.argv[2]) {
console.log('Specify directory to check')
process.exit()
}
var dpath = path.resolve(process.cwd(), process.argv[2])
var api = {
read: (dpath) => new Promise((resolve, reject) => {
fs.readdir(dpath, (err, names) => err
? reject(err)
: resolve(names.map((name) => path.resolve(dpath, name))))
})
,
check: (dpath) => new Promise((resolve, reject) => {
cp.exec(
'git status',
{cwd: dpath},
(err, stdout, stderr) => (err || stderr)
? reject(err || stderr)
: resolve({dpath, status: stdout})
)
})
,
}
// main
api.read(dpath)
.then((dirs) => Promise.all(dirs.map(api.check)))
.then((statuses) => statuses
.filter(({status}) => !/nothing to commit, working tree clean/.test(status))
.map(({dpath}) => console.log(dpath))
)
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment