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

Appearance settings

Commit eebdb25

Browse filesBrowse files
committed
Eliminate duplication of git.util.cwd logic
1 parent c7fad20 commit eebdb25
Copy full SHA for eebdb25

File tree

2 files changed

+3
-14
lines changed
Filter options

2 files changed

+3
-14
lines changed

‎git/util.py

Copy file name to clipboardExpand all lines: git/util.py
+1Lines 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
def cwd(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

Copy file name to clipboardExpand all lines: test/test_git.py
+2-14Lines 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-
import contextlib
87
import os
98
import shutil
109
import subprocess
@@ -15,24 +14,13 @@
1514
from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
1615
from test.lib import TestBase, fixture_path
1716
from test.lib import with_rw_directory
18-
from git.util import finalize_process
17+
from git.util import cwd, finalize_process
1918

2019
import os.path as osp
2120

2221
from git.compat import is_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
class TestGit(TestBase):
3725
@classmethod
3826
def setUpClass(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+
with cwd(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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.