Skip to content

Should Repo.tags return tags sorted by date, not alphabetical? #185

Closed
@duncanmmacleod

Description

@duncanmmacleod

At present, git.Repo.tags returns the list of tags sorted alphabetically. It might be more helpful to have the list of tags sorted by the committed_date of the relevant Commit.

For example, I have a repository with the following tags:

>>> import git
>>> repo = git.Repo('.')
>>> print(repo.tags)
[<git.TagReference "refs/tags/v0.1a1">,
 <git.TagReference "refs/tags/v0.1a10">,
 <git.TagReference "refs/tags/v0.1a2">,
 <git.TagReference "refs/tags/v0.1a3">,
 <git.TagReference "refs/tags/v0.1a4">,
 <git.TagReference "refs/tags/v0.1a5">,
 <git.TagReference "refs/tags/v0.1a6">,
 <git.TagReference "refs/tags/v0.1a7">,
 <git.TagReference "refs/tags/v0.1a8">,
 <git.TagReference "refs/tags/v0.1a9">]

Here the ordering is misleading, since the v0.1a10 tag is the most recent. Does it make sense to sort this list before returning?

>>> print(sorted(repo.tags, key=lambda t: t.commit.committed_date))
[<git.TagReference "refs/tags/v0.1a1">,
 <git.TagReference "refs/tags/v0.1a2">,
 <git.TagReference "refs/tags/v0.1a3">,
 <git.TagReference "refs/tags/v0.1a4">,
 <git.TagReference "refs/tags/v0.1a5">,
 <git.TagReference "refs/tags/v0.1a6">,
 <git.TagReference "refs/tags/v0.1a7">,
 <git.TagReference "refs/tags/v0.1a8">,
 <git.TagReference "refs/tags/v0.1a9">,
 <git.TagReference "refs/tags/v0.1a10">]

This may also be helpful for other reference lists.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions