Skip to content

Commit 0ddbe4b

Browse files
committed
Added test for sshkey context manager.
It verifies that the script is actually called. Interestingly, the shell script version works within an msysgit environment on windows. Fixes #234
1 parent 5ad07f7 commit 0ddbe4b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Diff for: git/repo/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def _expand_path(p):
7575

7676

7777
class Repo(object):
78-
7978
"""Represents a git repository and allows you to query references,
8079
gather commit information, generate diffs, create and clone repositories query
8180
the log.
@@ -758,7 +757,7 @@ def init(cls, path=None, mkdir=True, **kwargs):
758757
# git command automatically chdir into the directory
759758
git = Git(path)
760759
git.init(**kwargs)
761-
return Repo(path)
760+
return cls(path)
762761

763762
@classmethod
764763
def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):

Diff for: git/test/test_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_references_and_objects(self, rw_dir):
440440
# [32-test_references_and_objects]
441441
private_key_file = os.path.join(rw_dir, 'id_rsa_deployment_key')
442442
with repo.git.sshkey(private_key_file):
443-
# Note that we don't actually make the call here, as our test-setup doesn't permit it to
443+
# Note that we don't actually make the call here, as our test-setup doesn't permit it to
444444
# succeed.
445445
# It will in your case :)
446446
repo.remotes.origin.fetch

Diff for: git/test/test_git.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,26 @@ def test_environment(self, rw_dir):
181181
assert new_env == {'VARKEY': 'VARVALUE'}
182182
assert self.git.environment() == {}
183183

184-
rw_repo = Repo.init(os.path.join(rw_dir, 'repo'))
184+
class TestRepo(Repo):
185+
class GitCommandWrapperType(Git):
186+
def _sshkey_script_path(self):
187+
path = os.path.join(rw_dir, 'failing-script.sh')
188+
stream = open(path, 'wt')
189+
stream.write("#!/usr/bin/env sh\n" +
190+
"echo FOO\n")
191+
stream.close()
192+
os.chmod(path, 0o555)
193+
return path
194+
# end Git
195+
# end Repo
196+
197+
rw_repo = TestRepo.init(os.path.join(rw_dir, 'repo'))
185198
remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo")
186199

187200
with rw_repo.git.sshkey('doesntexist.key'):
188-
remote.fetch()
201+
try:
202+
remote.fetch()
203+
except GitCommandError as err:
204+
assert 'FOO' in str(err)
205+
# end
189206
# end
190-
191-

0 commit comments

Comments
 (0)