Skip to content

Commit

Permalink
GitReadCommand: fix DescribeHeadWithTagWithExclude
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Dec 1, 2023
1 parent 1a25aeb commit 2e001fe
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ abstract class GitReadCommand implements ValueSource<String, GitCommandParameter
commandLineArgs.addAll(args)
execOperations.exec {
it.setCommandLine(commandLineArgs)
it.ignoreExitValue = true
it.standardOutput = output
it.errorOutput = error
}
Expand All @@ -37,6 +36,28 @@ abstract class GitReadCommand implements ValueSource<String, GitCommandParameter
}
return new String(output.toByteArray(), Charset.defaultCharset())
}

@CompileDynamic
String executeGitCommandWithErrorIgnore(Object ... args) {
File rootDir = parameters.rootDir.get()
ByteArrayOutputStream output = new ByteArrayOutputStream()
ByteArrayOutputStream error = new ByteArrayOutputStream()
List<String> commandLineArgs = ["git", "--git-dir=${rootDir.absolutePath}/.git".toString(), "--work-tree=${rootDir.absolutePath}".toString()]
commandLineArgs.addAll(args)
execOperations.exec {
it.setCommandLine(commandLineArgs)
it.standardOutput = output
it.errorOutput = error
}
String result = new String(output.toByteArray(), Charset.defaultCharset())
if(result) {
return result
}
def errorMsg = new String(error.toByteArray(), Charset.defaultCharset())
if(errorMsg) {
throw new GradleException(errorMsg)
}
}
}

/**
Expand Down Expand Up @@ -74,7 +95,7 @@ abstract class DescribeHeadWithTagWithExclude extends GitReadCommand {
@Override
String obtain() {
try {
return executeGitCommand( "describe", "HEAD", "--tags", "--long", "--exclude", "\"*-rc.*\"")
return executeGitCommandWithErrorIgnore( "describe", "HEAD", "--tags", "--long", "--exclude", "*-rc.*")
} catch (Exception e) {
return null
}
Expand Down

0 comments on commit 2e001fe

Please sign in to comment.