1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-25 15:52:06 +01:00

gradle: Ensure git command is run projectDir rather than CWD.

The assert on line 659 was causing my build to fail. Two issues caused
gitCommit to be empty.

1. The cmd 'git describe --always --tags --dirty=+' was not given
   enough time to complete and had not exited which meant no text in
   proc.text
2. The two git commands on lines 653 and 658 were run from the
   CWD of my Eclipse IDE, not the $projectDir which caused git to return
   an error 128.

To solve the two issues I added a waitForOrKill method call to
proc (like the srCmd had) and I set the execute to run in $projectDir
which I think was the intent/assumption in the original code.

Also add waitFor on git describe command.
This commit is contained in:
John Haubrich 2019-10-10 08:46:47 -04:00 committed by Florian Schmaus
parent b510d373b5
commit 7a58862794

View file

@ -650,13 +650,16 @@ def getGitCommit() {
def dotGit = new File("$projectDir/.git") def dotGit = new File("$projectDir/.git")
if (!dotGit.isDirectory()) return 'non-git build' if (!dotGit.isDirectory()) return 'non-git build'
def projectDir = dotGit.getParentFile()
def cmd = 'git describe --always --tags --dirty=+' def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute() def proc = cmd.execute(null, projectDir)
proc.waitForOrKill(10 * 1000)
def gitCommit = proc.text.trim() def gitCommit = proc.text.trim()
assert !gitCommit.isEmpty() assert !gitCommit.isEmpty()
def srCmd = 'git symbolic-ref --short HEAD' def srCmd = 'git symbolic-ref --short HEAD'
def srProc = srCmd.execute() def srProc = srCmd.execute(null, projectDir)
srProc.waitForOrKill(10 * 1000) srProc.waitForOrKill(10 * 1000)
if (srProc.exitValue() == 0) { if (srProc.exitValue() == 0) {
// Only add the information if the git command was // Only add the information if the git command was