Created
February 9, 2012 23:50
-
-
Save Dierk/1784418 to your computer and use it in GitHub Desktop.
a pre-receive hook to allow both: feature branches and agile CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a git pre-receive hook | |
// that automatically merges all pushes to feature branches | |
// into a dedicated continuous-integration (ci) branch. | |
// Since we cannot merge in a bare repo, we work on a temporary clone. | |
// Dierk Koenig | |
def ciBranch = 'master' | |
def mergeName = 'merge' | |
def hereDirPath = new File('.').canonicalPath | |
def tempDir = new File('../temp') | |
def mergeDir = new File(tempDir, mergeName) | |
System.in.eachLine { line -> | |
def (parent, commit, ref) = line.split() | |
def branch = ref.split('/').last() | |
// pushes to the ciBranch are not merged - cut endless loop | |
if (branch == ciBranch) System.exit(0) | |
println "branch $branch was pushed: auto-merge into $ciBranch" | |
cmd "rm -rf $tempDir.canonicalPath" | |
tempDir.mkdirs() | |
cmd "git clone -b $ciBranch $hereDirPath $mergeName", tempDir | |
cmd "git merge $commit", mergeDir | |
cmd "git push origin $ciBranch", mergeDir | |
println "done" | |
} | |
void cmd(String command, File dir = null) { | |
Process proc = command.execute([], dir) | |
if (dir) println "in dir: $dir.canonicalPath" | |
println command | |
proc.waitFor() | |
def out = proc.in.text; if (out) println out | |
def err = proc.err.text; if (err) println "! $err" | |
if (proc.exitValue()) System.exit(1) | |
} |
a) there are a lot of scripts where an additional jvm startup time (~ 1 second on my machine) is not relevant. The above is one example.
b) groovyserv eliminates even this additional second and has always worked reliably for me.
Yeah, I thought a pre-receive would block the client which is pushing. Now if you tell me you're using groovyserv for your hooks… sounds like I'm gonna have to convert my hooks ! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please excuse the OT nature of my comment, but I've been considering using groovy for hooks myself, but abandoned the idea (without even trying tbh): how do you deal with vm startup time ? I thought of groovyserv but doesn't it have problems executing scripts concurrently ?