Skip to content

Commit 5451c92

Browse files
committed
handle cases when unset by default
1 parent b2b7066 commit 5451c92

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

codeflash/code_utils/git_worktree_utils.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import configparser
4+
35
import subprocess
46
import tempfile
57
import time
@@ -19,10 +21,18 @@
1921
def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None:
2022
repository = git.Repo(worktree_dir, search_parent_directories=True)
2123
username = None
24+
no_username = False
2225
email = None
26+
no_email = False
2327
with repository.config_reader() as cr:
24-
username = cr.get("user", "name")
25-
email = cr.get("user", "email")
28+
try:
29+
username = cr.get("user", "name")
30+
except configparser.NoSectionError:
31+
no_username = True
32+
try:
33+
email = cr.get("user", "email")
34+
except configparser.NoSectionError:
35+
no_email = True
2636
repository.git.config()
2737
with repository.config_writer() as cw:
2838
if not cw.has_option("user", "name"):
@@ -35,8 +45,12 @@ def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) ->
3545
with repository.config_writer() as cw:
3646
if username:
3747
cw.set_value("user", "name", username)
48+
elif no_username:
49+
cw.remove_option("user", "name")
3850
if email:
3951
cw.set_value("user", "email", email)
52+
elif no_email:
53+
cw.remove_option("user", "email")
4054

4155

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

0 commit comments

Comments
 (0)