Skip to content
Patrick Stadler edited this page Jan 29, 2015 · 1 revision

Abort if local repository is dirty

plan.local(function(local) {
  var repoStatus = local.exec('test -z "$(git status --porcelain)"', {failsafe: true});
  if(repoStatus.code !== 0) {
    local.log('You local repository is dirty.');
    plan.abort();
  }
}); 

Abort if local branch is not synced with the remote branch

plan.local(function(local) {
  var branchName = local.git('rev-parse --abbrev-ref HEAD').stdout.trim();
  var localRefHash = local.git('rev-parse HEAD').stdout.trim();
  var remoteRefHash =  local.git('ls-remote origin -h refs/heads/' +
                                          branchName + ' | cut -f1').stdout;
  if(localRefHash !== remoteRefHash) {
    local.log('Your local repository is not up-to-date. Sync with remote first.');
    plan.abort();
  }
}); 

Only allow the master branch to be deployed to the production target

plan.local(function(local) {
  var branchName = local.git('rev-parse --abbrev-ref HEAD').stdout.trim();
  if(plan.runtime.target === 'production' && branchName !== 'master') {
    local.log("You can't deploy anything else than master to production.");
    plan.abort();
  }
}); 
Clone this wiki locally