@@ -124,11 +124,14 @@ def setup_logging():
124124
125125
126126def init_git_user ():
127- """Initialize Git user configuration globally and update PAT status."""
127+ """Initialize Git user configuration for the repository and update PAT status."""
128128 logger = logging .getLogger (__name__ )
129129 logger .info ("Starting Git user configuration" )
130130
131131 try :
132+ from .config import config
133+ repo_path = config .DB_DIR
134+
132135 git_name = os .environ .get ('GIT_USER_NAME' , 'Profilarr' )
133136 git_email = os .environ .get ('GIT_USER_EMAIL' ,
134137 'profilarr@dictionarry.com' )
@@ -139,30 +142,38 @@ def init_git_user():
139142 if git_name == 'Profilarr' or git_email == 'profilarr@dictionarry.com' :
140143 logger .info ("Using default Git user configuration" )
141144
142- # Set global Git configuration
143- subprocess .run (['git' , 'config' , '--global' , 'user.name' , git_name ],
144- check = True )
145- subprocess .run (['git' , 'config' , '--global' , 'user.email' , git_email ],
146- check = True )
145+ # Set repository-level Git configuration if repo exists
146+ if os .path .exists (os .path .join (repo_path , '.git' )):
147+ logger .info (f"Setting git config for repository at { repo_path } " )
148+ subprocess .run (['git' , '-C' , repo_path , 'config' , '--local' , 'user.name' , git_name ],
149+ check = True )
150+ subprocess .run (['git' , '-C' , repo_path , 'config' , '--local' , 'user.email' , git_email ],
151+ check = True )
152+ # Add safe.directory to prevent ownership issues
153+ subprocess .run (['git' , '-C' , repo_path , 'config' , '--local' , '--add' , 'safe.directory' , repo_path ],
154+ check = True )
155+ else :
156+ logger .warning (f"No git repository found at { repo_path } , skipping git config" )
147157
148158 # Update PAT status in database
149159 update_pat_status ()
150160
151- # Verify configuration
152- configured_name = subprocess .run (
153- ['git' , 'config' , '--global' , 'user.name' ],
154- capture_output = True ,
155- text = True ,
156- check = True ).stdout .strip ()
157- configured_email = subprocess .run (
158- ['git' , 'config' , '--global' , 'user.email' ],
159- capture_output = True ,
160- text = True ,
161- check = True ).stdout .strip ()
162-
163- if configured_name != git_name or configured_email != git_email :
164- logger .error ("Git configuration verification failed" )
165- return False , "Git configuration verification failed"
161+ # Verify configuration if repository exists
162+ if os .path .exists (os .path .join (repo_path , '.git' )):
163+ configured_name = subprocess .run (
164+ ['git' , '-C' , repo_path , 'config' , '--local' , 'user.name' ],
165+ capture_output = True ,
166+ text = True ,
167+ check = True ).stdout .strip ()
168+ configured_email = subprocess .run (
169+ ['git' , '-C' , repo_path , 'config' , '--local' , 'user.email' ],
170+ capture_output = True ,
171+ text = True ,
172+ check = True ).stdout .strip ()
173+
174+ if configured_name != git_name or configured_email != git_email :
175+ logger .error ("Git configuration verification failed" )
176+ return False , "Git configuration verification failed"
166177
167178 logger .info ("Git user configuration completed successfully" )
168179 return True , "Git configuration successful"
0 commit comments