Skip to content

Instantly share code, notes, and snippets.

@jacekkow
Created September 6, 2015 21:36
Show Gist options
  • Save jacekkow/f63d9f64ac1489d5ee21 to your computer and use it in GitHub Desktop.
Save jacekkow/f63d9f64ac1489d5ee21 to your computer and use it in GitHub Desktop.
import java.io.File
import java.lang.Runtime
import org.eclipse.jgit.lib.Repository
logger.info("post-update: post-receive hook executing post-update script in git repository.")
Repository repo = gitblit.getRepository(repository.name)
File repoPath = new File(repo.directory.canonicalPath)
File updateHook = new File(repoPath, "hooks" + File.separator + "post-update")
logger.info("post-update: repository path: ${repoPath}")
if (updateHook.canExecute()) {
logger.info("post-update: executing ${updateHook}")
Process process = Runtime.getRuntime().exec([updateHook.getPath()], null, repoPath)
process.waitFor()
int exitValue = process.exitValue()
if (exitValue != 0) {
logger.error("post-update: ${updateHook} exited with code ${exitValue}")
} else {
logger.info("post update: execution succeeded")
}
} else {
logger.info("post-update: hook not executable, nothing to do.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment