gitglob

How to solve git describe --match limitation


I'm using git describe --long --tags to automatically generate version strings from repo tags. So that if I have 1.20 tag I get 1.20-5-g27ba6e8 version string in my code.

Now I'm only interested in tags which in regexish look like ^\d+\.\d+$ (I don't want describe to see any other descriptive tags).

git describe has --match switch which would have been exactly what I need if not for the fact that the match is done using glob patterns.

How can I limit a glob pattern only to two numbers (which can have any number of digits!) delimited with a dot?


Solution

  • I know it's been over 3 years this question was asked, but I stumbled upon it only today looking into a similar problem and the answer is: yes, you can (it's just not as straightforward as it would have been with regex support).

    You need several globs to gradually narrow down on the desired pattern.

    Specifically for the problem in this question, here is the filter:

    git describe --tags --exclude=*[!0-9.]* --exclude=*\.*\.* --match=v[0-9]*\.[0-9]*
    

    You may want to add an exclude or two more to this to filter out "malformed" versions like 1.01 or 00.0 (semver, for example, does not allow leading zeros), but the key idea is the same: can't match due to the glob limitations? then exclude.