Re: [feature request] Is it possible to have git tag can be sorted and filtered by semver?
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 22, 2024, 23:40 UTC
- Message-ID
- <xmqqy15t6lmz.fsf@gitster.g>
- In-Reply-To
- <031701dadc8c$db6d3370$92479a50$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
Show 14 quoted lines
> Currently, tags would be sorted as follows (simple example): > 1.10.0 > 1.2.0 > 1.9.1 > > With semver, the tags would be: > 1.2.0 > 1.9.1 > 1.10.0 > > My take is that this, if implemented, would need to be more general, and include prefix and suffix handling, so: > v1.2.0 > v1.9.0 > v1.10.0
Without implemeting anything, wouldn't "--sort=version:refname" suggested by Brian work just fine?
In the git repository:
$ git tag --sort=version:refname | grep -e 'v2\.[0-9][0-9]*\.[0-9][0-9]*$'
v2.0.0
...
v2.0.5
v2.1.0
v2.1.1
v2.1.2
v2.1.3
v2.1.4
v2.2.0
...
v2.9.0
...
v2.9.5
v2.10.0
v2.10.1
v2.10.2
v2.10.3
v2.10.4
v2.10.5
v2.11.0
...
v2.45.1
v2.45.2sorting 2.1.x series a lot earlier than 2.10.x series that is sorted after 2.9.x series.
Isn't it exactly what the original requester wants to see?
One mechanism I find it lacking is a mechanism to tell the tool that -preW in X.Y.Z-preW is a suffix that signals that X.Y.Z-preW comes before X.Y.Z, while -postW in X.Y.Z-postW is a suffix that signals that X.Y.Z-postW comes after X.Y.Z. Using such a mechanism, we could say v2.1.0-rc0 comes before v2.1.0-rc1, which in turn comes before v2.1.0-rc2, which in turn comes before v2.1.0 proper.
But other than the ordering of the final release and -rcX, I think "--sort=version:refname" does the right thing already.