@@ -28,7 +28,7 @@ def tearDown(self):
2828 shutil .rmtree (self .test_dir )
2929
3030 def test_init (self ):
31- repo .init ()
31+ repo .init (force_creation = True )
3232
3333 # Check if a git repository was created
3434 self .assertTrue ((self .test_dir / '.git' ).is_dir ())
@@ -40,19 +40,25 @@ def test_init(self):
4040 self .assertEqual (len (commits ), 1 )
4141 self .assertEqual (commits [0 ].message , f"{ repo .INITIAL_COMMIT_MESSAGE } { repo .AUTOMATION_NOTE } " )
4242
43+ def test_init_parent_repo_exists (self ):
44+ os .makedirs (self .test_dir .parent / '.git' )
45+
46+ repo .init (force_creation = False )
47+ self .assertFalse ((self .test_dir / '.git' ).is_dir ())
48+
4349 def test_get_repo_nonexistent (self ):
4450 with self .assertRaises (EnvironmentError ):
4551 repo ._get_repo ()
4652
4753 def test_get_repo_existent (self ):
48- repo .init ()
54+ repo .init (force_creation = True )
4955
5056 result = repo ._get_repo ()
5157 self .assertIsInstance (result , git .Repo )
5258 self .assertEqual (result .working_tree_dir , str (self .test_dir ))
5359
5460 def test_get_uncommitted_files_new_file (self ):
55- repo .init ()
61+ repo .init (force_creation = True )
5662
5763 new_file = self .test_dir / "new_file.txt"
5864 new_file .touch ()
@@ -62,7 +68,7 @@ def test_get_uncommitted_files_new_file(self):
6268 self .assertIn ("new_file.txt" , uncommitted )
6369
6470 def test_get_uncommitted_files_modified_file (self ):
65- repo .init ()
71+ repo .init (force_creation = True )
6672
6773 # Create and commit an initial file
6874 initial_file = self .test_dir / "initial_file.txt"
@@ -154,7 +160,7 @@ def test_require_git_installed(self, mock_which, mock_should_track):
154160 repo ._require_git ()
155161
156162 def test_transaction_context_manager (self ):
157- repo .init ()
163+ repo .init (force_creation = True )
158164 mock_commit = MagicMock ()
159165
160166 with patch ('agentstack.repo.commit' , mock_commit ):
@@ -165,7 +171,7 @@ def test_transaction_context_manager(self):
165171 mock_commit .assert_called_once_with (f"Test message" , ["test_file.txt" ], automated = True )
166172
167173 def test_transaction_multiple_messages (self ):
168- repo .init ()
174+ repo .init (force_creation = True )
169175 mock_commit = MagicMock ()
170176
171177 with patch ('agentstack.repo.commit' , mock_commit ):
@@ -180,7 +186,7 @@ def test_transaction_multiple_messages(self):
180186 )
181187
182188 def test_transaction_no_changes (self ):
183- repo .init ()
189+ repo .init (force_creation = True )
184190 mock_commit = MagicMock ()
185191
186192 with patch ('agentstack.repo.commit' , mock_commit ):
@@ -192,7 +198,7 @@ def test_transaction_no_changes(self):
192198 mock_commit .assert_not_called ()
193199
194200 def test_transaction_with_exception (self ):
195- repo .init ()
201+ repo .init (force_creation = True )
196202 mock_commit = MagicMock ()
197203
198204 with patch ('agentstack.repo.commit' , mock_commit ):
@@ -212,7 +218,7 @@ def test_transaction_with_exception(self):
212218
213219 def test_init_when_git_disabled (self ):
214220 repo .dont_track_changes ()
215- result = repo .init ()
221+ result = repo .init (force_creation = True )
216222 self .assertIsNone (result )
217223 repo ._USE_GIT = None # Reset for other tests
218224
@@ -235,7 +241,7 @@ def test_get_uncommitted_files_when_git_disabled(self):
235241 repo ._USE_GIT = None # Reset for other tests
236242
237243 def test_commit_user_changes (self ):
238- repo .init ()
244+ repo .init (force_creation = True )
239245
240246 # Create a new file
241247 test_file = self .test_dir / "user_file.txt"
0 commit comments