Reputation: 820
We can get the last git tag, which starts by a word(e.g TEST) as follow:
git describe --tag --dirty --match 'TEST*'
I am wondering how can I get the last tag, which starts by word1 or word2 (e.g. TEST OR RUN)? I've tried to use regex or following but it does not work:
git describe --tag --dirty --match 'TEST*|RUN*'
SOLUTION: We can get number of commits to HEAD and compare those numbers, the one which has less commits is the more recently. You can find its script in the answer, which I have added.
Upvotes: 3
Views: 4110
Reputation: 1329712
Note: only Git 2.15 (Q4 2017) will allow multiple patterns:
"
git describe --match
" learned to take multiple patterns in v2.13 series, but the feature ignored the patterns after the first one and did not work at all. This has been fixed.
See commit da769d2 (16 Sep 2017) by Max Kirillov (max630
).
(Merged by Junio C Hamano -- gitster
-- in commit a515136, 28 Sep 2017)
git describe --long --tags --match="test1-*" --match="test2-*" HEAD^
In your case:
git describe --long --tags --match="TEST*" --match="RUN*"
Upvotes: 1
Reputation: 820
We can get number of commits to HEAD and compare those numbers, the one which has less commits is the more recently, as follow:
#!/bin/bash
V_TEST=$(git describe --tag --dirty --match 'TEST*' | awk 'BEGIN { FS = "-" }; {print $2}')
V_RUN=$(git describe --tag --dirty --match 'RUN*' | awk 'BEGIN { FS = "-" }; {print $2}')
if [[ $V_TEST -gt $V_RUN ]] ; then
VERSION=$(git describe --tag --dirty --match 'RUN*')
echo $VERSION
else
VERSION=$(git describe --tag --dirty --match 'TEST*')
fi
echo $VERSION
Upvotes: 1
Reputation: 36422
The pattern is matched using fnmatch()
, which uses shell wildcard patterns, not regular expressions.
As shell wildcards don't support alternation you can't do this without changing the implementation of describe
.
Source: git describe source :P
Upvotes: 1
Reputation: 2621
If I understand you correctly, you could probably do something along the lines of:
/^git describe --tag --dirty --match '(?:TEST|RUN)\*'$/
Live demo and explanation: http://regex101.com/r/qC3gW5
Upvotes: -1