|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import configparser |
3 | 4 | import subprocess |
4 | 5 | import tempfile |
5 | 6 | import time |
|
18 | 19 |
|
19 | 20 | def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None: |
20 | 21 | repository = git.Repo(worktree_dir, search_parent_directories=True) |
21 | | - with repository.config_writer() as cw: |
| 22 | + username = None |
| 23 | + no_username = False |
| 24 | + email = None |
| 25 | + no_email = False |
| 26 | + with repository.config_reader(config_level="repository") as cr: |
| 27 | + try: |
| 28 | + username = cr.get("user", "name") |
| 29 | + except configparser.NoSectionError: |
| 30 | + no_username = True |
| 31 | + try: |
| 32 | + email = cr.get("user", "email") |
| 33 | + except configparser.NoSectionError: |
| 34 | + no_email = True |
| 35 | + with repository.config_writer(config_level="repository") as cw: |
22 | 36 | if not cw.has_option("user", "name"): |
23 | 37 | cw.set_value("user", "name", "Codeflash Bot") |
24 | 38 | if not cw.has_option("user", "email"): |
25 | 39 | cw.set_value("user", "email", "bot@codeflash.ai") |
26 | 40 |
|
27 | 41 | repository.git.add(".") |
28 | 42 | repository.git.commit("-m", commit_message, "--no-verify") |
| 43 | + with repository.config_writer(config_level="repository") as cw: |
| 44 | + if username: |
| 45 | + cw.set_value("user", "name", username) |
| 46 | + elif no_username: |
| 47 | + cw.remove_option("user", "name") |
| 48 | + if email: |
| 49 | + cw.set_value("user", "email", email) |
| 50 | + elif no_email: |
| 51 | + cw.remove_option("user", "email") |
29 | 52 |
|
30 | 53 |
|
31 | 54 | def create_detached_worktree(module_root: Path) -> Optional[Path]: |
|
0 commit comments