Skip to content

Commit

Permalink
[CHORE] check if local master branch synced with remote, before push …
Browse files Browse the repository at this point in the history
…to less/css branches
  • Loading branch information
dmh committed Jun 16, 2016
1 parent a700387 commit 295ff2c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions grunt/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pushSite:
# Provide all Front-End service files plus CSS styling for CMS needs, copy it to separate branch "css" and push it to remote git server.
# ==================================
pushCss:
- 'checkMaster' #task helper
#Dev
- 'dev' #task helper
#Postcss autoprefixer
Expand All @@ -84,6 +85,7 @@ pushCss:
# Provide all Front-End service files plus LESS styling for CMS needs, copy it to separate branch "less" and push it to remote git server.
# ==================================
pushLess:
- 'checkMaster' #task helper
#Dev
- 'dev' #task helper
#Less
Expand Down Expand Up @@ -138,5 +140,12 @@ pushLessBranch:
- 'buildcontrol:less'
- 'notify:less'

# check is local master branch synced with remote master
checkMaster:
# check Is Master
- 'shell:isMaster'
# check is Updated
- 'shell:isUpdated'

# ==================================
# ==================================
55 changes: 55 additions & 0 deletions grunt/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function isMaster(err, stdout, stderr, cb) {
if (err) {
cb(err);
return;
}
var match = stdout.match(/\n/i);
stdout = stdout.slice(0, match.index);
if (stdout === 'master') {
cb();
return;
} else {
console.log('You are not at master brunch!');
console.log('Please switch to master branch and start script again.');
cb();
process.exit();
}
}
function isUpdated(err, stdout, stderr, cb) {
if (err) {
cb(err);
return;
}
var match = stdout.match(/\n/i);
stdout = stdout.slice(0, match.index);
var matchAhead = stdout.match(/ahead/i);
if (!matchAhead) {
cb();
return;
} else {
console.log('Error!');
console.log('Your local master branch is not synchronized with remote master.');
console.log('Please push you changes to remote repo (git push), and start script again.');
cb();
process.exit();
}
}

module.exports = {
isMaster: {
command: 'git rev-parse --abbrev-ref HEAD',
options: {
stderr: false,
stdout: false,
callback: isMaster
}
},
isUpdated: {
command: 'git status -sb',
options: {
stderr: false,
stdout: false,
callback: isUpdated
}
}
};

0 comments on commit 295ff2c

Please sign in to comment.