Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getStagedFileList (patterns, ignorePatterns) {
const baseDir = getBaseDir()
// 如果 baseDir 根本不存在 sgf 会抛出异常
if (!fs.existsSync(baseDir)) {
return Promise.resolve([])
}
sgf.cwd = baseDir
return new Promise(resolve => {
sgf((err, result) => {
if (err) {
debug('staged-git-files error: %o', err)
return resolve([])
}
const fileList = result
.filter(item => item.status !== 'Deleted') // 过滤已删除的文件
.filter(item => match(item.filename, patterns, ignorePatterns))
.map(item => item.filename)
resolve(fileList)
})
})
module.exports = function (options) {
var stream = through.obj();
sgf.cwd = process.cwd();
sgf(function(err, results) {
if (err) { return stream.emit('error', err); }
var files = results.map(function (file) {
return file.filename;
});
if (files.length === 0) {
return stream.end();
}
fs.src(files, options).pipe(stream);
});
return stream;
function getStageFiles(cb) {
const gitDir = findParentDir.sync(process.cwd(), '.git');
sgf.cwd = gitDir
let stageFiles = [];
sgf('ACM', (err, files) => {
if (files) {
stageFiles = files.map(item => {
return item.filename
})
}
cb(err, stageFiles);
});
}