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

Add in doco examples for how to clone a remote repo using a proxy #1328

Closed
davidcba1 opened this issue Nov 25, 2024 · 3 comments · Fixed by #1354
Closed

Add in doco examples for how to clone a remote repo using a proxy #1328

davidcba1 opened this issue Nov 25, 2024 · 3 comments · Fixed by #1354

Comments

@davidcba1
Copy link

Hey,

I'm trying to work out how to use pygit2 to clone a remote repo using a proxy, i'm looking at some of the examples and I need to define a username/password which is fine but I can't work out how to use the proxy setting as well.

I'm referencing the following articles, but going around in circles

This one for user/pass
https://www.pygit2.org/recipes/git-clone-ssh.html

This one for remotes
https://www.pygit2.org/recipes/git-clone-mirror.html

and in the doco these bits
https://www.pygit2.org/remotes.html#pygit2.Remote.connect
https://www.pygit2.org/repository.html#pygit2.clone_repository

So this is 1 asking for guidance, but also a "recipe" for how to do this for future users.

@Tsafaras
Copy link

Can you describe what you're trying to accomplish in more detail?
And what you're struggling with?

If your problem is about the proxy's username/pass, shouldn't that be part of the proxy's URL?
For example (extending the one from the docs):

proxy = f"http://{USER}:{PASS}@proxy.example.org:3128"

@davidcba1
Copy link
Author

davidcba1 commented Feb 19, 2025

Hey,

We can't talk to github.com unless we go via an authed proxy and we were unable to get pygit2 to work. We did try examples like this - but when running it we couldn't even see the attempt going out via a proxy it was still trying to go direct. Its still very possible we were doing things wrong, but other parts of the code were honoring both the proxy from the https_proxy env vars and the manually set ones in code.

We have pivoted and coding things differently to get around this, but having a real working example in what I linked would help future users. if they hit the same issues.

I don't need this issue open anymore, so if there's no value seen then it may be closed.

sathieu added a commit to sathieu/pygit2 that referenced this issue Mar 6, 2025
@sathieu
Copy link
Contributor

sathieu commented Mar 6, 2025

@davidcba1 There is currently no one-line way to clone thru a proxy. I've created #1354 for this.

In the meantime, you can use something like:

from pygit2 import Commit, init_repository
from pygit2.enums import ResetMode


url = "https://github.com/libgit2/TestGitRepository"
dest = "TestGitRepository"
main_branch = "master"

repo = init_repository(dest, initial_head=main_branch, origin_url=url)
repo.remotes["origin"].fetch(proxy=True)
main_commit = repo.branches[f"origin/{main_branch}"].peel(Commit)
repo.branches.create(main_branch , main_commit)
repo.reset(main_commit.id, ResetMode.HARD)

sathieu added a commit to sathieu/pygit2 that referenced this issue Mar 6, 2025
@jdavid jdavid closed this as completed in db587ad Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants