mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
Added GitTemporaryDirectory
This commit is contained in:
parent
86cea01434
commit
a9cca05680
2 changed files with 59 additions and 30 deletions
|
@ -1,5 +1,10 @@
|
|||
import os
|
||||
import tempfile
|
||||
|
||||
import git
|
||||
|
||||
from aider.dump import dump # noqa: F401
|
||||
|
||||
|
||||
class IgnorantTemporaryDirectory:
|
||||
def __init__(self):
|
||||
|
@ -13,3 +18,29 @@ class IgnorantTemporaryDirectory:
|
|||
self.temp_dir.__exit__(exc_type, exc_val, exc_tb)
|
||||
except OSError:
|
||||
pass # Ignore errors (Windows)
|
||||
|
||||
|
||||
class ChdirTemporaryDirectory(IgnorantTemporaryDirectory):
|
||||
def __init__(self):
|
||||
self.cwd = os.getcwd()
|
||||
super().__init__()
|
||||
|
||||
def __enter__(self):
|
||||
res = super().__enter__()
|
||||
os.chdir(self.temp_dir.name)
|
||||
return res
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
os.chdir(self.cwd)
|
||||
super().__exit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
|
||||
class GitTemporaryDirectory(ChdirTemporaryDirectory):
|
||||
def __enter__(self):
|
||||
res = super().__enter__()
|
||||
|
||||
repo = git.Repo.init()
|
||||
repo.config_writer().set_value("user", "name", "Test User").release()
|
||||
repo.config_writer().set_value("user", "email", "testuser@example.com").release()
|
||||
|
||||
return res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue