@@ -321,28 +321,30 @@ def save_credentials_to_file(
321321 # containing the .gitignore file, add the relative path to the
322322 # .gitignore file
323323 rel = default_paths .osw_files_dir .relative_to (containing_gitignore )
324- to_add = f"\n *{ str (rel .as_posix ())} /*"
324+ to_add = f"\n */ { str (rel .as_posix ())} /*"
325325 else :
326326 # Test if the default_path.osw_files_dir is a subdirectory of the
327327 # directory containing the .gitignore file
328328 to_add = (
329329 f"\n */{ default_paths .osw_files_dir .absolute ().as_posix ()} /*"
330330 )
331331 osw_dir_added = True
332- elif f"*/ { fp . name } " not in content :
332+ else :
333333 print (f"Adding '{ fp .name } ' to gitignore file '{ gitignore_fp } '." )
334334 to_add = f"\n */{ fp .name } "
335- # If to_add is not empty, write to .gitignore file
336- if to_add :
337- with open (gitignore_fp , "a" ) as stream :
338- # Only add comment if not already set
339- if not comment_set :
340- stream .write (
341- "\n # Automatically added by osw.auth.CredentialManager."
342- "save_credentials_to_file:"
343- )
344- comment_set = True
345- stream .write (to_add )
335+ if not to_add or to_add in content :
336+ continue
337+
338+ with open (gitignore_fp , "a" ) as stream :
339+ # Only add comment if not already set
340+ comment = (
341+ "\n # Automatically added by osw.auth.CredentialManager."
342+ "save_credentials_to_file:"
343+ )
344+ if not comment_set and comment not in content :
345+ stream .write (comment )
346+ comment_set = True
347+ stream .write (to_add )
346348
347349
348350CredentialManager .CredentialConfig .update_forward_refs ()
0 commit comments