3

groovyでgitshellコマンドを実行しようとしています。1つ目は正常に実行されますが、2つ目は終了コード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()

このコードの何が問題になっていますか?

4

1 に答える 1

4

最初のプロセスが完了する前に、2 番目のプロセスが開始されています。2 番目の 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.

最初のタスクが完了するのを待ってから 2 番目のタスクを開始すると、うまくいくはずです。このようなもの:

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()
于 2014-04-16T22:09:34.170 に答える