From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Thaina Yu <thainayu@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [feature request] Is it possible to have git tag can be sorted and filtered by semver?
Date: Mon, 22 Jul 2024 21:30:43 +0000 [thread overview]
Message-ID: <Zp7Pg7ZOlBZcfJei@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <CADeMgjBeyWkE3mp+-x57NSsyNLQf3cTta+Xm5uyVOQE-rpT6yg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1605 bytes --]
On 2024-07-22 at 16:58:11, Thaina Yu wrote:
> Currently there is `ls-remote` and `tag` that has option to
> --sort=version:refname which is really useful when we have tag as
> version format and let it sort as numeric version
>
> But it could be better if we can also sort and filter the version in
> the range of semver format. So we can use git system as dependency
> management system natively
>
> So I would like to propose a new sort option semver:refname
>
> `git ls-remote --sort=semver:refname myRepoUrl refs/tags/v{^0.*.*}`
> where brace {} can be used to define semver versioning ranges for the
> patterns in addition to glob filter
Assuming we add such a feature, how does sorting by SemVer differ from
the current version sorting? That is, where is the current version
sorting deficient for SemVer? Also, what do you want to happen when a
tag doesn't meet SemVer requirements (note that the "v" prefix is not
allowed in SemVer, although it's customary in tags)?
As for the special range syntax, I think the typical suggestion is to
filter the output of ls-remote or for-each-ref by piping it to a
suitable program. Perl or Ruby are common choices here, and both could
easily parse SemVer tags. For example:
git for-each-ref --sort=v:refname refs/tags/ |
ruby -ne 'if %r[\trefs/tags/v(\d+)\.(\d+)\.(\d+)$]; ver = Regexp.last_match[1..3].map(&:to_i); puts $_ if [[2, 6, 3], ver, [2, 15, 2]].sort[1] == ver; end'
Git is intentionally designed to support this kind of shell scripting.
--
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2024-07-22 21:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 16:58 [feature request] Is it possible to have git tag can be sorted and filtered by semver? Thaina Yu
2024-07-22 21:30 ` brian m. carlson [this message]
2024-07-22 23:14 ` rsbecker
2024-07-22 23:40 ` Junio C Hamano
2024-07-23 0:05 ` brian m. carlson
2024-07-23 3:06 ` Thaina Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zp7Pg7ZOlBZcfJei@tapette.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=thainayu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox