Last active
May 31, 2018 19:16
-
-
Save z-hao-wang/8979a1288f3bae4e1f910495d1bff11d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const git = require('nodegit-kit'); | |
const { exec } = require('child_process'); | |
async function getCurrentBranchName() { | |
return new Promise(resolve => { | |
exec('git branch | grep \\*', function(err, stdout, stderr) { | |
resolve(stdout.replace('* ', '')); | |
}); | |
}); | |
} | |
async function getChangeFiles() { | |
const repo = await git.open(__dirname + '/../../../'); | |
const masterHistory = await git.log(repo, { branch: 'master', 'max-count': 1 }); | |
const currentBranchName = await getCurrentBranchName(); | |
const currentBranchHistory = await git.log(repo, { branch: currentBranchName.trim(), 'max-count': 1 }); | |
const diff = await git.diff(repo, masterHistory[0], currentBranchHistory[0]); | |
const changedFiles = diff.map(file => file.path); | |
console.info('ChangedFiles:'); | |
console.info(changedFiles.join('\n')); | |
return changedFiles; | |
} | |
module.exports = getChangeFiles; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment