StuStirling
StuStirling

Reputation: 16191

Use `git describe --match` In Android build.gradle

Having trouble getting the latest git tag that matches a glob passed in to git describe within Gradle. It works fine when in terminal.

I have tried the following:

project.ext.releaseVersionName = "git describe --match \'[0-9]*.[0-9]*.[0-9]*\' --abbrev=0 --tags".execute().text.trim()

And

def getReleaseVersion = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'bash', '-c', 'git', 'describe', '--match "[0-9]*.[0-9]*.[0-9]*"', '--abbrev=0', 'HEAD'
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }
    catch (ignored) {
        return null
    }
}

However both return empty strings. If I don't have the match then everything works correctly. I think it's the glob thats causing the issues.

Upvotes: 2

Views: 313

Answers (1)

mmlr
mmlr

Reputation: 2155

By having the whole of '--match "[0-9]*.[0-9]*.[0-9]*"' in single quotes, you are basically passing an option with that whole string. What you really want is probably to pass the option --match with an argument of [0-9]*.[0-9]*.[0-9]*. You should therefore split that argument so that your commandLine becomes:

commandLine 'git', 'describe', '--match', '[0-9]*.[0-9]*.[0-9]*', '--abbrev=0', 'HEAD'

Alternatively you could switch the --match argument to the --arg=value syntax, i.e. use --match=[0-9]*.[0-9]*.[0-9]* like you do for --abbrev=0.

I've removed the 'bash', '-c' part as per the comments. If 'bash', '-c' was to be used, the whole rest should be a single string, as it would work as the value to the -c argument of bash.

Upvotes: 1

Related Questions