Skip to content

Instantly share code, notes, and snippets.

@xavierzwirtz
Created October 19, 2015 15:51
Show Gist options
  • Save xavierzwirtz/9d1d776fca021c9d42a1 to your computer and use it in GitHub Desktop.
Save xavierzwirtz/9d1d776fca021c9d42a1 to your computer and use it in GitHub Desktop.
'use strict';
var _ = require('lodash');
var argv = require('yargs').argv;
var exec = require('child_process').exec;
module.exports = function(gulp) {
gulp.task('mercurial-tag', function(done) {
var buildLabel = argv.build_label;
if (_.isUndefined(buildLabel)) {
throw 'label is required for versioning';
}
var message = 'Tagging build ' + buildLabel;
var tag = buildLabel;
exec('hg revert --all', function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
exec('hg tag --force --message "' + message + '" "' + tag + '"', function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
done();
});
});
});
gulp.task('mercurial-push', function(done) {
var attemptPush = function(currentTry, maxTry) {
if (currentTry > maxTry) {
throw 'Took more than ' + maxTry + ' to push.';
}
exec('hg pull', function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
exec('hg heads . --template "." --topo', function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
var headCount = stdout.match(/\./g).length;
var push = function() {
exec('hg push --branch .', function(error, stdout, stderr) {
if (error !== null) {
console.log('Error pushing to remote, trying again.');
attemptPush(currentTry + 1, maxTry);
}
done();
});
};
if (headCount > 1) {
var mergeCommand = 'hg merge ';
mergeCommand += '--config "merge-patterns..hgtags=merge-tags" ';
mergeCommand += '--config "merge-tools.merge-tags.executable=powershell.exe" ';
mergeCommand += '--config "merge-tools.merge-tags.args=-ExecutionPolicy Unrestricted -File .\\Scripts\\MergeTags.ps1 -local \\"$local\\" -other \\"$other\\" -output \\"$output\\""';
exec(mergeCommand, function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
exec('hg commit -m "Merge"', function(error, stdout, stderr) {
if (error !== null) {
throw error;
}
push();
});
});
} else {
push();
}
});
});
};
attemptPush(1, 10);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment