Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion codeflash/code_utils/git_worktree_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import configparser
import subprocess
import tempfile
import time
Expand All @@ -18,14 +19,36 @@

def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None:
repository = git.Repo(worktree_dir, search_parent_directories=True)
with repository.config_writer() as cw:
username = None
no_username = False
email = None
no_email = False
with repository.config_reader(config_level="repository") as cr:
try:
username = cr.get("user", "name")
except configparser.NoSectionError:
no_username = True
try:
email = cr.get("user", "email")
except configparser.NoSectionError:
no_email = True
with repository.config_writer(config_level="repository") as cw:
if not cw.has_option("user", "name"):
cw.set_value("user", "name", "Codeflash Bot")
if not cw.has_option("user", "email"):
cw.set_value("user", "email", "[email protected]")

repository.git.add(".")
repository.git.commit("-m", commit_message, "--no-verify")
with repository.config_writer(config_level="repository") as cw:
if username:
cw.set_value("user", "name", username)
elif no_username:
cw.remove_option("user", "name")
if email:
cw.set_value("user", "email", email)
elif no_email:
cw.remove_option("user", "email")


def create_detached_worktree(module_root: Path) -> Optional[Path]:
Expand Down
Loading