0

I'm not seeing anything in the docs for how to just get the repo name: https://www.pygit2.org/repository.html

Is reading the origin remote and parsing it out the only way pygit supports this or is there a more reliable or specific property for this?

myrepo = Repository(".")
for remote in myrepo.remotes:
    if remote.name == "origin":
        print(remote.url)
        # now parse git@bitbucket.org:mybb-workspace/myrepo.git ??
red888
  • 27,709
  • 55
  • 204
  • 392
  • What do you mean by "the repo name"? What are you trying to pull out of the remote URL? – ChrisGPT was on strike Dec 22 '22 at 16:59
  • 1
    There's no guarantee that a given repository has a remote called `origin`, or any remotes at all for that matter. Assuming "the repo name" here is supposed to be `myrepo`, why does it matter what that name is? What are you trying to do with it? – ChrisGPT was on strike Dec 22 '22 at 17:00
  • The repo name as it is in my source control provider. I plan on using it for metadata stuff and other things that require source control info. When a repo is cloned is origin the default remote name always or is that not the case? – red888 Dec 22 '22 at 17:23
  • There's no guarantee that a remote defines a "repo name" as such, either. A remote can just be another directory on the same machine. Remotes have a name (e.g. `origin`) and a URL. In general, that's all you can assume. I'd probably use the name and URL as my metadata and leave it at that. – ChrisGPT was on strike Dec 22 '22 at 17:56
  • "When a repo is cloned is origin the default remote name always or is that not the case?"—that's the default, but it [can be overridden](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt--oltnamegt). – ChrisGPT was on strike Dec 22 '22 at 20:11

0 Answers0