UNPKG

cybertron-utils

Version:
33 lines (28 loc) 899 B
const execSync = require('child_process').execSync; exports.hasGit = () => { const gitMessage = execSync('git remote -v', { encoding: 'utf8' }); const remoteList = gitMessage.split('\n'); let fetchUrl = null; for (let i = 0; i < remoteList.length; i++) { if (remoteList[i].includes('(fetch)') && remoteList[i].includes('origin')) { fetchUrl = remoteList[i].match(/(ssh|http|https).*\.git/); if (fetchUrl) { fetchUrl = fetchUrl[0]; } } } return fetchUrl; } exports.getCommitHash = () => { return execSync('git rev-parse HEAD', { encoding: 'utf8' }); } exports.checkIsPush = () => { const gitStatus = execSync('git status', { encoding: 'utf8' }); if(gitStatus.indexOf('nothing to commit, working tree clean') !== -1){ const gitDiff = execSync('git diff origin/master...HEAD --name-status', { encoding: 'utf8' }); if(!gitDiff){ return true; } } return false; }