Skip to content

Commit

Permalink
Removed Git.sshkey() as it couldn't be distributed properly.
Browse files Browse the repository at this point in the history
However, I kept information on how to achieve the same thing with
`custom_environment()` in the test.

Related to #234
  • Loading branch information
Byron committed Jan 22, 2015
1 parent f3d91ca commit 4df4159
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 44 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include CHANGES
include AUTHORS
include README
include requirements.txt
include git/scripts/ssh_wrapper.sh

graft git/test/fixtures
graft git/test/performance
2 changes: 1 addition & 1 deletion doc/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ You can easily access configuration information for a remote by accessing option
:start-after: # [26-test_references_and_objects]
:end-before: # ![26-test_references_and_objects]

You can also specify an SSH key to use for any operations on the remotes
You can also specify per-call custom environments using a new context manager on the Git command

.. literalinclude:: ../../git/test/test_docs.py
:language: python
Expand Down
21 changes: 0 additions & 21 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ def _set_cache_(self, attr):
super(Git, self)._set_cache_(attr)
# END handle version info

def _sshkey_script_path(self):
this_dir = os.path.dirname(__file__)
return os.path.join(this_dir, 'scripts', 'ssh_wrapper.sh')

@property
def working_dir(self):
""":return: Git directory we are working on"""
Expand Down Expand Up @@ -670,23 +666,6 @@ def custom_environment(self, **kwargs):
finally:
self.update_environment(**old_env)

@contextmanager
def sshkey(self, sshkey_file_path):
"""
A context manager to temporarily set an SSH key for all operations that
run inside it.
``Examples``::
with self.sshkey('deployment_key'):
repo.remotes.origin.fetch()
:param sshkey_file_path: Path to a private SSH key file
"""
ssh_wrapper = self._sshkey_script_path()
with self.custom_environment(GIT_SSH_KEY_FILE=sshkey_file_path, GIT_SSH=ssh_wrapper):
yield

def transform_kwargs(self, split_single_char_options=False, **kwargs):
"""Transforms Python style kwargs into git command line options."""
args = list()
Expand Down
2 changes: 1 addition & 1 deletion git/ext/gitdb
Submodule gitdb updated 1 files
+6 −0 README.rst
2 changes: 0 additions & 2 deletions git/scripts/ssh_wrapper.sh

This file was deleted.

4 changes: 2 additions & 2 deletions git/test/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ def test_references_and_objects(self, rw_dir):
# ![31-test_references_and_objects]

# [32-test_references_and_objects]
private_key_file = os.path.join(rw_dir, 'id_rsa_deployment_key')
with repo.git.sshkey(private_key_file):
ssh_executable = os.path.join(rw_dir, 'my_ssh_executable.sh')
with repo.git.custom_environment(GIT_SSH=ssh_executable):
# Note that we don't actually make the call here, as our test-setup doesn't permit it to
# succeed.
# It will in your case :)
Expand Down
24 changes: 9 additions & 15 deletions git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,17 @@ def test_environment(self, rw_dir):
assert new_env == {'VARKEY': 'VARVALUE'}
assert self.git.environment() == {}

class TestRepo(Repo):
class GitCommandWrapperType(Git):
def _sshkey_script_path(self):
path = os.path.join(rw_dir, 'failing-script.sh')
stream = open(path, 'wt')
stream.write("#!/usr/bin/env sh\n" +
"echo FOO\n")
stream.close()
os.chmod(path, 0o555)
return path
# end Git
# end Repo

rw_repo = TestRepo.init(os.path.join(rw_dir, 'repo'))
path = os.path.join(rw_dir, 'failing-script.sh')
stream = open(path, 'wt')
stream.write("#!/usr/bin/env sh\n" +
"echo FOO\n")
stream.close()
os.chmod(path, 0o555)

rw_repo = Repo.init(os.path.join(rw_dir, 'repo'))
remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo")

with rw_repo.git.sshkey('doesntexist.key'):
with rw_repo.git.custom_environment(GIT_SSH=path):
try:
remote.fetch()
except GitCommandError as err:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _stamp_version(filename):
url="https://github.com/gitpython-developers/GitPython",
packages=find_packages('.'),
py_modules=['git.' + f[:-3] for f in os.listdir('./git') if f.endswith('.py')],
package_data={'git.test': ['fixtures/*'], 'git' : ['scripts/*']},
package_data={'git.test': ['fixtures/*']},
package_dir={'git': 'git'},
license="BSD License",
requires=['gitdb (>=0.6.4)'],
Expand Down

0 comments on commit 4df4159

Please sign in to comment.