Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ce3fe7

Browse files
committed
Intermediate commit on my way to get this finalized.
Renamed context manager 'with_environment' to 'custom_environment'.On my way to implement sshkey test.
1 parent6f03861 commit2ce3fe7

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

‎doc/source/tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ Change configuration for a specific remote only::
384384
385385
o.config_writer.set("pushurl", "other_url")
386386

387-
You can also specify an SSH key to use for any operations on the remotes:
387+
You can also specify an SSH key to use for any operations on the remotes::
388388

389389
private_key_file = project_dir+'id_rsa_deployment_key'
390390
with repo.git.sshkey(private_key_file):

‎git/cmd.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ def _set_cache_(self, attr):
439439
super(Git,self)._set_cache_(attr)
440440
# END handle version info
441441

442+
def_sshkey_script_path(self):
443+
this_dir=os.path.dirname(__file__)
444+
returnos.path.join(this_dir,'scripts','ssh_wrapper.sh')
445+
442446
@property
443447
defworking_dir(self):
444448
""":return: Git directory we are working on"""
@@ -541,6 +545,7 @@ def execute(self, command,
541545
# Start the process
542546
env=os.environ.copy()
543547
env["LC_MESSAGES"]="C"
548+
print(self._environment)
544549
env.update(self._environment)
545550

546551
proc=Popen(command,
@@ -633,7 +638,7 @@ def update_environment(self, **kwargs):
633638
:return: dict that maps environment variables to their old values
634639
"""
635640
old_env= {}
636-
forkey,valueinkwargs.iteritems():
641+
forkey,valueinkwargs.items():
637642
# set value if it is None
638643
ifvalueisnotNone:
639644
ifkeyinself._environment:
@@ -648,14 +653,14 @@ def update_environment(self, **kwargs):
648653
returnold_env
649654

650655
@contextmanager
651-
defwith_environment(self,**kwargs):
656+
defcustom_environment(self,**kwargs):
652657
"""
653-
A context manager around the above update_environment to restore the
658+
A context manager around the above``update_environment`` method to restore the
654659
environment back to its previous state after operation.
655660
656661
``Examples``::
657662
658-
with self.with_environment(GIT_SSH='/bin/ssh_wrapper'):
663+
with self.custom_environment(GIT_SSH='/bin/ssh_wrapper'):
659664
repo.remotes.origin.fetch()
660665
661666
:param kwargs: see update_environment
@@ -667,22 +672,20 @@ def with_environment(self, **kwargs):
667672
self.update_environment(**old_env)
668673

669674
@contextmanager
670-
defsshkey(self,sshkey_file):
675+
defsshkey(self,sshkey_file_path):
671676
"""
672677
A context manager to temporarily set an SSH key for all operations that
673678
run inside it.
674679
675680
``Examples``::
676681
677-
with self.environment(GIT_SSH=project_dir+'deployment_key'):
682+
with self.sshkey('deployment_key'):
678683
repo.remotes.origin.fetch()
679684
680-
:paramsshkey_file: Path to a private SSH key file
685+
:paramsshkey_file_path: Path to a private SSH key file
681686
"""
682-
this_dir=os.path.dirname(__file__)
683-
ssh_wrapper=os.path.join(this_dir,'..','scripts','ssh_wrapper.py')
684-
685-
withself.with_environment(GIT_SSH_KEY_FILE=sshkey_file,GIT_SSH=ssh_wrapper):
687+
ssh_wrapper=self._sshkey_script_path()
688+
withself.custom_environment(GIT_SSH_KEY_FILE=sshkey_file_path,GIT_SSH=ssh_wrapper):
686689
yield
687690

688691
deftransform_kwargs(self,split_single_char_options=False,**kwargs):

‎git/scripts/ssh_wrapper.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+
ssh -i"$GIT_SSH_KEY_FILE"$@

‎git/test/test_git.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
7-
87
importos
98
importmock
10-
fromgit.test.libimport (TestBase,
11-
patch,
12-
raises,
13-
assert_equal,
14-
assert_true,
15-
assert_match,
16-
fixture_path)
17-
fromgitimport (Git,
18-
GitCommandError)
9+
10+
fromgit.test.libimport (
11+
TestBase,
12+
patch,
13+
raises,
14+
assert_equal,
15+
assert_true,
16+
assert_match,
17+
fixture_path
18+
)
19+
fromgitimport (
20+
Git,
21+
GitCommandError,
22+
Repo
23+
)
24+
fromgitdb.test.libimportwith_rw_directory
1925

2026
fromgit.compatimportPY3
2127

@@ -154,12 +160,13 @@ def test_env_vars_passed_to_git(self):
154160
withmock.patch.dict('os.environ', {'GIT_EDITOR':editor}):
155161
assertself.git.var("GIT_EDITOR")==editor
156162

157-
deftest_environment(self):
163+
@with_rw_directory
164+
deftest_environment(self,rw_dir):
158165
# sanity check
159166
assertself.git.environment()== {}
160167

161168
# make sure the context manager works and cleans up after itself
162-
withself.git.with_environment(PWD='/tmp'):
169+
withself.git.custom_environment(PWD='/tmp'):
163170
assertself.git.environment()== {'PWD':'/tmp'}
164171

165172
assertself.git.environment()== {}
@@ -173,3 +180,12 @@ def test_environment(self):
173180
new_env=self.git.update_environment(**old_env)
174181
assertnew_env== {'VARKEY':'VARVALUE'}
175182
assertself.git.environment()== {}
183+
184+
rw_repo=Repo.init(os.path.join(rw_dir,'repo'))
185+
remote=rw_repo.create_remote('ssh-origin',"ssh://git@server/foo")
186+
187+
withrw_repo.git.sshkey('doesntexist.key'):
188+
remote.fetch()
189+
# end
190+
191+

‎scripts/ssh_wrapper.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp