-
-
Notifications
You must be signed in to change notification settings - Fork 969
Add a first-class API to get the latest tag from a remote via git ls-remote
#2119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -995,6 +995,28 @@ def __getattribute__(self, name: str) -> Any: | |||||||||||||||||||||||||||
| _warn_use_shell(extra_danger=False) | ||||||||||||||||||||||||||||
| return super().__getattribute__(name) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def latest_remote_tag(self, repository: PathLike) -> Optional[str]: | ||||||||||||||||||||||||||||
| output = self.ls_remote("--tags", "--sort=-version:refname", repository) | ||||||||||||||||||||||||||||
|
Comment on lines
+998
to
+999
|
||||||||||||||||||||||||||||
| def latest_remote_tag(self, repository: PathLike) -> Optional[str]: | |
| output = self.ls_remote("--tags", "--sort=-version:refname", repository) | |
| def latest_remote_tag( | |
| self, | |
| repository: PathLike, | |
| allow_unsafe_protocols: bool = False, | |
| ) -> Optional[str]: | |
| repo_str = os.fspath(repository) | |
| if repo_str.startswith("ext::") and not allow_unsafe_protocols: | |
| raise UnsafeProtocolError( | |
| f"Refusing to use unsafe protocol for repository {repo_str!r}" | |
| ) | |
| output = self.ls_remote("--tags", "--sort=-version:refname", "--", repo_str) |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces new parsing/selection behavior (handling empty output, malformed lines, and peeled ^{} refs) but there are no tests covering it. Since the project already has extensive Git wrapper tests (e.g. test/test_git.py), please add unit tests that mock Git.execute/ls_remote output to cover: empty output, a peeled annotated tag appearing first, and malformed lines being ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new public convenience method has no docstring, but nearby public methods in
Gitare documented. Please add a docstring clarifying what “latest” means (it relies on--sort=-version:refname), how annotated tags are handled, and whenNoneis returned.