最初のプロセスが完了する前に、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()