Support git command
MongoSh is a developer tool, obviously. So as a developer, git is always a part of it. Supporting git command inside mongosh will help us save a lot of time.
Here's some of my implementation:
const git = (command) => {
try {
return execSync(`git ${command}`).toString();
} catch (e) {};
return null;
};
const listBranches = () => {
const branches = git(`branch -a`).split(/\r\n|\n|\r/).filter(notEmpty);
return branches.map(branchObj);
};
const pull = (remote = 'origin') => {
return git(`pull ${remote} --rebase`);
};
const log = (cnt) => {
const _cnt = Number(cnt) || 32;
return git(`log --graph --all --oneline --decorate=short --max-count=${_cnt}`);
}