| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c7fad20 commit eebdb25
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -150,6 +150,7 @@ def wrapper(self: "Remote", *args: Any, **kwargs: Any) -> T: | |||
| 150 | 150 | ||
| 151 | 151 | @contextlib.contextmanager | |
| 152 | 152 | def cwd(new_dir: PathLike) -> Generator[PathLike, None, None]: | |
| 153 | + """Context manager to temporarily change directory. Not reentrant.""" | ||
| 153 | 154 | old_dir = os.getcwd() | |
| 154 | 155 | os.chdir(new_dir) | |
| 155 | 156 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | # | |
| 5 | 5 | # This module is part of GitPython and is released under | |
| 6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 7 | - import contextlib | ||
| 8 | 7 | import os | |
| 9 | 8 | import shutil | |
| 10 | 9 | import subprocess | |
@@ -15,24 +14,13 @@ | |||
| 15 | 14 | from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd | |
| 16 | 15 | from test.lib import TestBase, fixture_path | |
| 17 | 16 | from test.lib import with_rw_directory | |
| 18 | - from git.util import finalize_process | ||
| 17 | + from git.util import cwd, finalize_process | ||
| 19 | 18 | ||
| 20 | 19 | import os.path as osp | |
| 21 | 20 | ||
| 22 | 21 | from git.compat import is_win | |
| 23 | 22 | ||
| 24 | 23 | ||
| 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 | - | ||
| 36 | 24 | class TestGit(TestBase): | |
| 37 | 25 | @classmethod | |
| 38 | 26 | def setUpClass(cls): | |
@@ -102,7 +90,7 @@ def test_it_executes_git_not_from_cwd(self): | |||
| 102 | 90 | print("#!/bin/sh", file=file) | |
| 103 | 91 | os.chmod(impostor_path, 0o755) | |
| 104 | 92 | ||
| 105 | - with _chdir(tmpdir): | ||
| 93 | + with cwd(tmpdir): | ||
| 106 | 94 | self.assertRegex(self.git.execute(["git", "version"]), r"^git version\b") | |
| 107 | 95 | ||
| 108 | 96 | @skipUnless(is_win, "The regression only affected Windows, and this test logic is OS-specific.") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments