Skip to content

Instantly share code, notes, and snippets.

@cesarvr
Last active May 12, 2020 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarvr/7c2d3c329c2ccc4a0649f42099318b46 to your computer and use it in GitHub Desktop.
Save cesarvr/7c2d3c329c2ccc4a0649f42099318b46 to your computer and use it in GitHub Desktop.
const { spawn } = require('child_process');
function pull(action) {
const git = spawn('git', ['pull'])
git.stdout.on('data', function(data) {
let msg = data.toString()
console.log('[git pull]: ', msg)
if(!msg.includes('Already up to date.')){
action()
}
})
git.on('exit', function(data) {
console.log('[git pull]: exit ', data)
})
}
function push(remote, branch) {
const git = spawn('git', ['push', remote, branch])
git.stdout.on('data', function(data) {
let msg = data.toString()
console.log('[git error]: ', data)
})
git.on('data', function(data) {
console.log('[git push]: ', data)
})
git.on('exit', function(data) {
console.log('[git push]: exit ', data)
})
}
pull(() => console.log('do something !! '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment