11from __future__ import annotations
22
3+ import configparser
4+
35import subprocess
46import tempfile
57import time
1921def 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
4256def create_detached_worktree (module_root : Path ) -> Optional [Path ]:
0 commit comments