UNPKG

gitstrap-cli

Version:

A cli tool that allows you to easily sync with your upstream git repository

61 lines (52 loc) 1.19 kB
var child_process = require("child_process"); module.exports = function (branch) { if(!branch) { var branchCmd = child_process.spawnSync( "git", ["branch"], {encoding: 'utf8'}); if(branchCmd.status != 0) { if(branchCmd.error) console.log(branchCmd.error[1]); else console.log(branchCmd.output[2]); process.exit(1); } else { //console.log(branchCmd.output[1]); var branch = branchCmd.output[1].split('* ')[1]; var branch = branch.split('\n')[0]; } } var fetchCmd = child_process.spawnSync( "git", ["fetch", "upstream"], {encoding: 'utf8'}); if(fetchCmd.status != 0) { if(fetchCmd.error) console.log(fetchCmd.error[1]); else console.log(fetchCmd.output[2]); process.exit(1); } else { console.log(fetchCmd.output[1]); } var mergeCmd = child_process.spawnSync( "git", ["merge", "upstream/" + branch], {encoding: 'utf8'}); if(mergeCmd.status != 0) { if(mergeCmd.error) { console.log(mergeCmd.error[1]); } else { console.log(mergeCmd.output[1]); console.log(mergeCmd.output[2]); } process.exit(1); } else { console.log(mergeCmd.output[1]); } }