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}`);
}
![](https://secure.gravatar.com/avatar/8b6a8395776187961f35a7d34a11eb4e?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)