mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
(refs #115)Ensure exit status 1 on GitCommand error
This commit is contained in:
@@ -35,13 +35,29 @@ abstract class GitCommand(val command: String) extends Command {
|
|||||||
protected var out: OutputStream = null
|
protected var out: OutputStream = null
|
||||||
protected var callback: ExitCallback = null
|
protected var callback: ExitCallback = null
|
||||||
|
|
||||||
protected def runnable(user: String): Runnable
|
protected def runTask(user: String): Unit
|
||||||
|
|
||||||
|
private def newTask(user: String): Runnable = new Runnable {
|
||||||
|
override def run(): Unit = {
|
||||||
|
try {
|
||||||
|
runTask(user)
|
||||||
|
callback.onExit(0)
|
||||||
|
} catch {
|
||||||
|
case e: RepositoryNotFoundException =>
|
||||||
|
logger.info(e.getMessage)
|
||||||
|
callback.onExit(1, "Repository Not Found")
|
||||||
|
case e: Throwable =>
|
||||||
|
logger.info(e.getMessage, e)
|
||||||
|
callback.onExit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override def start(env: Environment): Unit = {
|
override def start(env: Environment): Unit = {
|
||||||
logger.info(s"start command : " + command)
|
logger.info(s"start command : " + command)
|
||||||
logger.info(s"parsed command : $gitCommand, $owner, $repositoryName")
|
logger.info(s"parsed command : $gitCommand, $owner, $repositoryName")
|
||||||
val user = env.getEnv.get("USER")
|
val user = env.getEnv.get("USER")
|
||||||
val thread = new Thread(runnable(user))
|
val thread = new Thread(newTask(user))
|
||||||
thread.start()
|
thread.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,59 +92,31 @@ abstract class GitCommand(val command: String) extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GitUploadPack(override val command: String) extends GitCommand(command: String) {
|
class GitUploadPack(override val command: String) extends GitCommand(command: String) {
|
||||||
override def runnable(user: String) = new Runnable {
|
|
||||||
override def run(): Unit = {
|
override protected def runTask(user: String): Unit = {
|
||||||
try {
|
using(Git.open(getRepositoryDir(owner, repositoryName))) {
|
||||||
using(Git.open(getRepositoryDir(owner, repositoryName))) {
|
git =>
|
||||||
git =>
|
val repository = git.getRepository
|
||||||
val repository = git.getRepository
|
val upload = new UploadPack(repository)
|
||||||
val upload = new UploadPack(repository)
|
upload.upload(in, out, err)
|
||||||
try {
|
|
||||||
upload.upload(in, out, err)
|
|
||||||
callback.onExit(0)
|
|
||||||
} catch {
|
|
||||||
case e: Throwable =>
|
|
||||||
logger.error(e.getMessage, e)
|
|
||||||
callback.onExit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
case e: RepositoryNotFoundException =>
|
|
||||||
logger.info(e.getMessage, e)
|
|
||||||
callback.onExit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitReceivePack(override val command: String) extends GitCommand(command: String) with SystemSettingsService {
|
class GitReceivePack(override val command: String) extends GitCommand(command: String) with SystemSettingsService {
|
||||||
// TODO Correct this info. where i get base url?
|
// TODO Correct this info. where i get base url?
|
||||||
val BaseURL: String = loadSystemSettings().baseUrl.getOrElse("http://localhost:8080")
|
val BaseURL: String = loadSystemSettings().baseUrl.getOrElse("http://localhost:8080")
|
||||||
|
|
||||||
override def runnable(user: String) = new Runnable {
|
override protected def runTask(user: String): Unit = {
|
||||||
override def run(): Unit = {
|
using(Git.open(getRepositoryDir(owner, repositoryName))) {
|
||||||
try {
|
git =>
|
||||||
using(Git.open(getRepositoryDir(owner, repositoryName))) {
|
val repository = git.getRepository
|
||||||
git =>
|
val receive = new ReceivePack(repository)
|
||||||
val repository = git.getRepository
|
receive.setPostReceiveHook(new CommitLogHook(owner, repositoryName, user, BaseURL))
|
||||||
val receive = new ReceivePack(repository)
|
Database(SshServer.getServletContext) withTransaction {
|
||||||
receive.setPostReceiveHook(new CommitLogHook(owner, repositoryName, user, BaseURL))
|
receive.receive(in, out, err)
|
||||||
Database(SshServer.getServletContext) withTransaction {
|
|
||||||
try {
|
|
||||||
receive.receive(in, out, err)
|
|
||||||
callback.onExit(0)
|
|
||||||
} catch {
|
|
||||||
case e: Throwable =>
|
|
||||||
logger.error(e.getMessage, e)
|
|
||||||
callback.onExit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
case e: RepositoryNotFoundException =>
|
|
||||||
logger.info(e.getMessage, e)
|
|
||||||
callback.onExit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user