@@ -290,3 +290,60 @@ def test_untracked_files_raises_exception(temp_repo):
290290 f .write ("Untracked file" )
291291 with pytest .raises (AssertionError , match = "Your repo has untracked files" ):
292292 packager .package (temp_repo , str (temp_repo ), "test" )
293+
294+
295+ @patch ("nemo_run.core.packaging.git.Context" , MockContext )
296+ def test_package_with_include_submodules (packager , temp_repo ):
297+ temp_repo = Path (temp_repo )
298+ # Create a submodule
299+ submodule_path = temp_repo / "submodule"
300+ submodule_path .mkdir ()
301+ os .chdir (str (submodule_path ))
302+ subprocess .check_call (["git" , "init" , "--initial-branch=main" ])
303+ open ("submodule_file.txt" , "w" ).write ("Submodule file" )
304+ subprocess .check_call (["git" , "add" , "." ])
305+ subprocess .check_call (["git" , "commit" , "-m" , "Initial submodule commit" ])
306+ os .chdir (str (temp_repo ))
307+ subprocess .check_call (["git" , "submodule" , "add" , str (submodule_path )])
308+ subprocess .check_call (["git" , "commit" , "-m" , "Add submodule" ])
309+
310+ packager = GitArchivePackager (ref = "HEAD" , include_submodules = True )
311+ with tempfile .TemporaryDirectory () as job_dir :
312+ output_file = packager .package (Path (temp_repo ), job_dir , "test_package" )
313+ assert os .path .exists (output_file )
314+ subprocess .check_call (shlex .split (f"mkdir -p { os .path .join (job_dir , 'extracted_output' )} " ))
315+ subprocess .check_call (
316+ shlex .split (f"tar -xvzf { output_file } -C { os .path .join (job_dir , 'extracted_output' )} " ),
317+ )
318+ cmp = filecmp .dircmp (
319+ os .path .join (temp_repo , "submodule" ),
320+ os .path .join (job_dir , "extracted_output" , "submodule" ),
321+ )
322+ assert cmp .left_list == cmp .right_list
323+ assert not cmp .diff_files
324+
325+
326+ @patch ("nemo_run.core.packaging.git.Context" , MockContext )
327+ def test_package_without_include_submodules (packager , temp_repo ):
328+ temp_repo = Path (temp_repo )
329+ # Create a submodule
330+ submodule_path = temp_repo / "submodule"
331+ submodule_path .mkdir ()
332+ os .chdir (str (submodule_path ))
333+ subprocess .check_call (["git" , "init" , "--initial-branch=main" ])
334+ open ("submodule_file.txt" , "w" ).write ("Submodule file" )
335+ subprocess .check_call (["git" , "add" , "." ])
336+ subprocess .check_call (["git" , "commit" , "-m" , "Initial submodule commit" ])
337+ os .chdir (str (temp_repo ))
338+ subprocess .check_call (["git" , "submodule" , "add" , str (submodule_path )])
339+ subprocess .check_call (["git" , "commit" , "-m" , "Add submodule" ])
340+
341+ packager = GitArchivePackager (ref = "HEAD" , include_submodules = False )
342+ with tempfile .TemporaryDirectory () as job_dir :
343+ output_file = packager .package (Path (temp_repo ), job_dir , "test_package" )
344+ assert os .path .exists (output_file )
345+ subprocess .check_call (shlex .split (f"mkdir -p { os .path .join (job_dir , 'extracted_output' )} " ))
346+ subprocess .check_call (
347+ shlex .split (f"tar -xvzf { output_file } -C { os .path .join (job_dir , 'extracted_output' )} " ),
348+ )
349+ assert len (os .listdir (os .path .join (job_dir , "extracted_output" , "submodule" ))) == 0
0 commit comments