Skip to content

Commit 4ca0a60

Browse files
Merge pull request #915 from codeflash-ai/git-commit-no-bot
only tag the single commit by codeflash bot and then revert to defaults
2 parents 8386af1 + afb7b04 commit 4ca0a60

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

codeflash/code_utils/git_worktree_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import configparser
34
import subprocess
45
import tempfile
56
import time
@@ -18,14 +19,36 @@
1819

1920
def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None:
2021
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:
2236
if not cw.has_option("user", "name"):
2337
cw.set_value("user", "name", "Codeflash Bot")
2438
if not cw.has_option("user", "email"):
2539
cw.set_value("user", "email", "bot@codeflash.ai")
2640

2741
repository.git.add(".")
2842
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")
2952

3053

3154
def create_detached_worktree(module_root: Path) -> Optional[Path]:

0 commit comments

Comments
 (0)