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

Commiteebdb25

Browse files
committed
Eliminate duplication of git.util.cwd logic
1 parentc7fad20 commiteebdb25

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

‎git/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def wrapper(self: "Remote", *args: Any, **kwargs: Any) -> T:
150150

151151
@contextlib.contextmanager
152152
defcwd(new_dir:PathLike)->Generator[PathLike,None,None]:
153+
"""Context manager to temporarily change directory. Not reentrant."""
153154
old_dir=os.getcwd()
154155
os.chdir(new_dir)
155156
try:

‎test/test_git.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
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-
importcontextlib
87
importos
98
importshutil
109
importsubprocess
@@ -15,24 +14,13 @@
1514
fromgitimportGit,refresh,GitCommandError,GitCommandNotFound,Repo,cmd
1615
fromtest.libimportTestBase,fixture_path
1716
fromtest.libimportwith_rw_directory
18-
fromgit.utilimportfinalize_process
17+
fromgit.utilimportcwd,finalize_process
1918

2019
importos.pathasosp
2120

2221
fromgit.compatimportis_win
2322

2423

25-
@contextlib.contextmanager
26-
def_chdir(new_dir):
27-
"""Context manager to temporarily change directory. Not reentrant."""
28-
old_dir=os.getcwd()
29-
os.chdir(new_dir)
30-
try:
31-
yield
32-
finally:
33-
os.chdir(old_dir)
34-
35-
3624
classTestGit(TestBase):
3725
@classmethod
3826
defsetUpClass(cls):
@@ -102,7 +90,7 @@ def test_it_executes_git_not_from_cwd(self):
10290
print("#!/bin/sh",file=file)
10391
os.chmod(impostor_path,0o755)
10492

105-
with_chdir(tmpdir):
93+
withcwd(tmpdir):
10694
self.assertRegex(self.git.execute(["git","version"]),r"^git version\b")
10795

10896
@skipUnless(is_win,"The regression only affected Windows, and this test logic is OS-specific.")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp