Search code examples
gitshellglob

Getting git tags that doesn't contain character


I'm trying to create a pattern to use with git ls-remote (git ls-remote -t origin "<mypattern>") to get the tags that do not end with -<number>. It needs to be with ls-remote because I'm trying to use it in a Jenkins pipeline that uses this command internally.

For example with following tags:

refs/tags/foo-bar-1.0.0
refs/tags/foo-bar-1.0.1-1
refs/tags/foo-bar-1.0.1-2
refs/tags/foo-bar-1.0.1
refs/tags/foo-bar-1.0.2

I would like to exclude the ones ending with -1 and -2.

I could to it easily with regex: foo-bar-\d+(.\d+){2}$, but the command doesn't accept regex.

I tried the patterns *foo-bar-*[!-]*" and *foo-bar-*.*.*[!-]* and they didn't work, they ended up getting all tags.

Am I missing something about the ! operator?


Solution

  • Shell globs are not powerful enough to do this. You need real regular expressions, or a programming language, to achieve what you want. You can easily invoke git ls-remote | grep from a shell: see Jenkins Pipeline Plugin: execute shell and parse output.