繁体   English   中英

Groovy执行git shell命令

[英]Groovy execute a git shell command

我正在尝试在groovy中执行git shell命令。 第一个执行得很好但第二个返回退出代码128:

   def workingDir = new File("path/to/dir")
   "git add .".execute(null, workingDir)
   def p = "git reset --hard".execute( null, workingDir )
   p.text.eachLine {println it}
   println p.exitValue()

这段代码有什么问题?

第二个过程在第一个过程完成之前开始。 当第二个git进程启动时,git会识别出已经有一个git进程在同一个目录中运行,这可能会导致问题,从而导致错误输出。 如果您从第一个进程读取错误流,您将看到如下内容:

fatal: Unable to create 'path/to/dir/.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

如果你在开始第二个之前等待第一个完成,那应该有效。 像这样的东西:

def workingDir = new File("path/to/dir/")

def p = "git add .".execute(null, workingDir)
p.waitFor()
p = "git reset --hard".execute( null, workingDir )
p.text.eachLine {println it}
println p.exitValue()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM