Skip to content

Commit

Permalink
Solve the url change problem in pygit2 fetch_refspec
Browse files Browse the repository at this point in the history
Because for now `pygit2` fetch didn't support `file://` format on
Windows, we removed this prefix. But didn't add it back after the
fetch operation finished, and it makes the following `dulwich`
backend goes wrong.

So here in the PR, we always create a new remote and delete it
after the operation to make the remote config unchanged after the
operation.
  • Loading branch information
karajan1001 committed Feb 6, 2023
1 parent 3d8c97c commit a2ba900
Showing 1 changed file with 14 additions and 14 deletions.
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

0 comments on commit a2ba900

Please sign in to comment.