Skip to content
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

Solve the url change problem in pygit2 fetch_refspec #177

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/scmrepo/git/backend/pygit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,24 @@ def _merge_remote_branch(
@contextmanager
def get_remote(self, url: str) -> Generator["Remote", None, None]:
try:
yield self.repo.remotes[url]
remote = self.repo.remotes[url]
url = remote.url
except ValueError:
try:
remote_name = uuid()
yield self.repo.remotes.create(remote_name, url)
finally:
self.repo.remotes.delete(remote_name)
pass
except KeyError:
raise SCMError(f"'{url}' is not a valid Git remote or URL")

if os.name == "nt" and url.startswith("ssh://"):
raise NotImplementedError
if os.name == "nt" and url.startswith("file://"):
url = url[len("file://") :]

try:
remote_name = uuid()
yield self.repo.remotes.create(remote_name, url)
finally:
self.repo.remotes.delete(remote_name)

def fetch_refspecs(
self,
url: str,
Expand All @@ -478,14 +486,6 @@ def fetch_refspecs(
refspecs = [refspecs]

with self.get_remote(url) as remote:
if os.name == "nt" and remote.url.startswith("ssh://"):
raise NotImplementedError

if os.name == "nt" and remote.url.startswith("file://"):
url = remote.url[len("file://") :]
self.repo.remotes.set_url(remote.name, url)
remote = self.repo.remotes[remote.name]

fetch_refspecs: List[str] = []
for refspec in refspecs:
if ":" in refspec:
Expand Down