2015-12-28 22:53:39 +01:00
|
|
|
import SimpleGit from 'simple-git';
|
|
|
|
import { promisify } from 'bluebird';
|
2015-12-28 23:31:36 +01:00
|
|
|
import { includes } from 'lodash';
|
2015-12-28 22:53:39 +01:00
|
|
|
|
|
|
|
export default function filesToCommit(path) {
|
|
|
|
const simpleGit = new SimpleGit(path);
|
|
|
|
const gitDiff = promisify(simpleGit.diff, simpleGit);
|
2016-02-10 23:32:58 +01:00
|
|
|
const pathsToIgnore = ['webpackShims'];
|
2015-12-28 22:53:39 +01:00
|
|
|
|
|
|
|
return gitDiff(['--name-status', '--cached'])
|
|
|
|
.then(output => {
|
|
|
|
return output
|
|
|
|
.split('\n')
|
|
|
|
.map(line => line.trim().split('\t'))
|
|
|
|
.filter(parts => parts.length === 2)
|
2016-02-10 23:32:58 +01:00
|
|
|
.filter(parts => {
|
|
|
|
return pathsToIgnore.reduce((prev, curr) => {(prev === false) ? prev : parts[1].indexOf(curr) === -1;}, true);
|
|
|
|
})
|
2015-12-28 22:53:39 +01:00
|
|
|
.map(parts => {
|
|
|
|
const status = parts.shift();
|
|
|
|
const name = parts.join('\t').trim();
|
|
|
|
return { status, name };
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getFilename(file) {
|
|
|
|
return file.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isAdded(file) {
|
|
|
|
return file.status === 'A';
|
|
|
|
};
|
|
|
|
|
|
|
|
export function isDeleted(file) {
|
|
|
|
return file.status === 'D';
|
|
|
|
}
|
2015-12-28 23:31:36 +01:00
|
|
|
|
|
|
|
export function isUnmerged(file) {
|
|
|
|
return file.status === 'U';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isStaged(file) {
|
|
|
|
return !isDeleted(file) && !isUnmerged(file);
|
|
|
|
}
|