HTTPS SSH

Gradle Mercurial Mq Plugin

A plugin for Gradle supporting basic Mercurial operations, including those related to MQ, Mercurial's patch queue manager. It has been released under the Apache Licence (v2) in the hope someone else might find it useful.

This plugin adds four new task types to your gradle build, HgPush, HgPull, HgTag and HgUpdate.

HgPush

Push changsets to one or more repositories.

HgPull

Pull changsets from a repository.

HgClone

Clone another repository.

HgTag

Tag a specific changeset.

HgUpdate

Get the working copy to a specified state, by indicating your desired combination of branch, patch guards, and patch name.

Installation

This plugin is available via the jcenter repository on Bintray. Using this repository is the easiest way to use this plugin. The example usage below uses jcenter.

Alternatively, you can download the source from https://bitbucket.org/coherentsoftware/gradle-mercurialmqplugin and build your own jar.

Building

The build system uses the Gradle wrapper. Therefore the only requirement is Java 6 or later.

./gradlew

will build the plugin.

Usage

Common to all MercurialMq tasks

import au.com.coherentsoftware.gradle.mercurial.task.*

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'au.com.coherentsoftware.gradle:Gradle-MercurialMqPlugin:VERSION'
    }
}

apply plugin: 'mercurial-mq'

mercurialmq {
    binary '/usr/bin/hg'  // the default value
}

HgPush Task

task pushChanges( type: HgPush ) {
    remotes ['publicRepo','devRepo','ssh://internal.com//var/hg/repo/data']
    workingDir = 'data'
}

HgPull Task

task pullChanges( type: HgPull ) {
    sourceUrl = 'ssh://internal.com//var/hg/repo/data'
    workingDir = 'data'
}

HgClone Task

task cloneProject( type: HgClone ) {
    sourceUrl = 'ssh://internal.com//var/hg/repo/data'
    workingDir = 'data'
}

task cloneWithPatches( type: HgClone ) {
    sourceUrl = 'ssh://internal.com//var/hg/repo/data'
    includePatchQueue = true
    workingDir = 'data'
}

HgTag Task

task tagCurrentRevision( type: HgTag ) {
    tag = "V${version}"
    workingDir = 'data
}

task tagSomeRevision( type: HgTag ) {
    tag = "V${version}"
    rev = project.revisionToTag
    workingDir = 'data
}

HgUpdate Task

task updateToDemoData( type: HgUpdate ) {
    workingDir = 'data'
    branch = 'default'
    guards = ['Standard','Demo']
    forceApply = true
}

task updateToTestData( type: HgUpdate ) {
    workingDir = 'data'
    guards = ['Standard','Test']
    forceApply = true
}

task updateToProductionData( type: HgUpdate ) {
    workingDir = 'data'
    branch = 'stable'
    guards = ['Standard']
}

task updateToDevPatch( type: HgUpdate ) {
    workingDir = 'data'
    targetPatch = 'devSettings'
    guards = ['Standard','Dev']
    forceApply = true
}

If forceApply is true, then any selected patches are applied, even if none were originally applied. Default behaviour is to apply patches during the update only if there were patches applied before the update.

The HgUpdate task will fail if the working directory has uncommitted changes.

Licence

This software is released under the Apache License, Version 2.0. Please see the copy of the licence, included in this directory as LICENSE, for details.

Bugs, Wishlist

Only supports one patch queue (the default).

If the patch queue is itself under version control, it must be managed by creating separate tasks, and being careful with the dependencies. Would be nice if the plugin were intelligent enough to do this itself.

Drives the commandline version of Mercurial, which is not particularly fast. However this seems to be only viable option, at least until something like Hg4J or JavaHg matures.

Feel free to fork and send pull requests! Home page on BitBucket at https://bitbucket.org/coherentsoftware/gradle-mercurialmqplugin

Contributors

Thank you to Tom Keschl for adding support for the clone operation.