git-js
git-js copied to clipboard
git add all
Hello,
Can we add the git.addAll
function as an alias to run git add --all
?
Also, git.commitAll
as an alias for git commit --all
.
+1
++ I solved the problem like this
import path from 'path';
import fs from 'fs';
const checkDirectorySync = (dir) => {
let err;
try {
fs.statSync(dir);
} catch (e) {
err = e;
}
return err === undefined ? true : false;
}
const gitRootPath = (dir) => {
dir = dir || path.resolve('.');
if (!checkDirectorySync(dir)) {
console.error('Error: Path is invalid');
process.exit(1);
}
if (checkDirectorySync(path.resolve(dir, '.git'))) {
return dir;
} else {
const parent = path.resolve(dir, '..');
if (parent === dir) {
console.error('Error: This directory is not a git repository');
process.exit(1);
}
return gitRootPath(parent);
}
};
export default gitRootPath;