- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 934
Repo.clone_from(env=...) doesn't have the desired effect #400
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
Comments
Hi @Neil511, indeed The problem mentioned here is also detailed, to some extend, in the gitpython tutorial, just look for As I believe this question is answered, I am closing the issue - please feel free to comment on it in case you need it reopened. |
@Byron: As far as I can tell, this cannot be done. I have worked around it in the meantime with:
However, I cannot use I have tried this:
NOGO - looks for wrong keys Also:
NOGO - looks for wrong keys Also:
NOGO - looks for wrong keys In the preceding scenarios, I have verified that The only thing that works is:
|
This seems to be a usability issue, as I do wonder whether you are using the latest version, as judging from the code, the |
Well I am using 1.0.2. I see there is a tag for 2.0.0, but when I
I get 1.0.2. That is odd since I see 2.0.0 is on PyPI, but even doing
I get When I get a chance I'll install from the repo tag and see if it changes. |
Thanks for letting me know, it seems we have got a bug at our hands. There is no test for this feature, so it might very well be it's broken. The workaround described here works as the git command will use the current environment as its basis when spawning git commands - good to know that this works at least. Regarding the installation issue: It should work now. Turns out I managed to not upload the actual file when creating the new release. |
I'm having [what I believe to be] the same issue on GitPython 2.0.2, but the workaround isn't working for me either. key_path = '/over/the/rainbow'
repo_path = 'git@github.com:foo/bar.git'
repo = Repo.init(repo_path)
origin = repo.create_remote('origin', url)
ssh_cmd = 'ssh -i ' + keypath
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
os.environ['GIT_SSH_COMMAND'] = ssh_cmd
print("GIT_SSH_COMMAND='" + ssh_cmd + '' git clone ' + url)
repo.remotes.origin.fetch() This returns: GIT_SSH_COMMAND='ssh -i /over/the/rainbow' git clone git@github.com:foo/bar.git
Traceback (most recent call last):
File "/opt/champagne/lib/main.py", line 35, in <module>
repo.remotes.origin.fetch()
File "/usr/local/lib/python3.4/dist-packages/git/remote.py", line 657, in fetch
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
File "/usr/local/lib/python3.4/dist-packages/git/remote.py", line 556, in _get_fetch_info_from_stderr
raise GitCommandError(("Error when fetching: %s" % line,), 2)
git.exc.GitCommandError: 'Error when fetching: fatal: Could not read from remote repository. Strangely enough, running |
Try using only the key_path = '/over/the/rainbow'
repo_path = 'git@github.com:foo/bar.git'
repo = Repo.init(repo_path)
origin = repo.create_remote('origin', url)
ssh_cmd = 'ssh -i ' + keypath
os.environ['GIT_SSH_COMMAND'] = ssh_cmd
print("GIT_SSH_COMMAND='" + ssh_cmd + '' git clone ' + url)
repo.remotes.origin.fetch() |
That did the trick, cheers @theherk! |
This is an odd one - I checked the code-path it is taking and could only see that it looks alright: The git process is always started with a customized environment, based on As you shouldn't have to change import pprint
pprint.pprint(env) This should make clear which environment is actually passed to help understanding what is going on here. |
@Byron I use python2.7 and gitpython2.0.8
this code doesn't work and doesn't hava debug log |
@woshihaoren I think what could work here is if you would import git after setting the environment variables, or by setting the environment variables from the shell invoking the python interpreter. Reason for that is that the environment variable is only read once at the time of import, and then cached in a similarly named class variable in the |
@Byron
|
I was wondering if there was an option or configuration in GitPython that allows you to specify what ssh key you would like to use for certain clones?
Example: I have a submodule that I would like to clone but it requires special access that I would like my script to employ. I need to allow access to anyone running the script and would like to avoid forcing users to setup an ssh config to do this.
Is there perhaps another way of tackling this problem that I'm unaware of?
The text was updated successfully, but these errors were encountered: