@@ -178,6 +178,7 @@ def test_collect_vcs_options(monkeypatch, run_task_mod, env, extra_expected):
178178 args = Namespace ()
179179 setattr (args , f"{ name } _checkout" , checkout )
180180 setattr (args , f"{ name } _sparse_profile" , False )
181+ setattr (args , f"{ name } _shallow_clone" , False )
181182
182183 result = run_task_mod .collect_vcs_options (args , name , name )
183184
@@ -193,6 +194,7 @@ def test_collect_vcs_options(monkeypatch, run_task_mod, env, extra_expected):
193194 "ref" : env .get ("HEAD_REF" ),
194195 "repo-type" : env .get ("REPOSITORY_TYPE" ),
195196 "revision" : env .get ("HEAD_REV" ),
197+ "shallow-clone" : False ,
196198 "ssh-secret-name" : env .get ("SSH_SECRET_NAME" ),
197199 "sparse-profile" : False ,
198200 "store-path" : env .get ("HG_STORE_PATH" ),
@@ -333,7 +335,9 @@ def mock_git_repo():
333335 )
334336
335337 def _commit_file (message , filename ):
336- with open (os .path .join (repo , filename ), "w" ) as fout :
338+ filepath = os .path .join (repo , filename )
339+ os .makedirs (os .path .dirname (filepath ), exist_ok = True )
340+ with open (filepath , "w" ) as fout :
337341 fout .write ("test file content" )
338342 subprocess .check_call (["git" , "add" , filename ], cwd = repo_path )
339343 subprocess .check_call (["git" , "commit" , "-m" , message ], cwd = repo_path )
@@ -420,6 +424,70 @@ def test_git_checkout_with_commit(
420424 )
421425
422426
427+ def test_git_checkout_shallow_clone (
428+ mock_stdin ,
429+ run_task_mod ,
430+ mock_git_repo ,
431+ ):
432+ """Test shallow clone option (not truly shallow with local repos due to git limitation)."""
433+ with tempfile .TemporaryDirectory () as workdir :
434+ destination = os .path .join (workdir , "destination" )
435+ # Note: shallow_clone with local repos doesn't work as expected due to git limitations
436+ # The --depth flag is ignored in local clones
437+ run_task_mod .git_checkout (
438+ destination_path = destination ,
439+ head_repo = mock_git_repo ["path" ],
440+ base_repo = mock_git_repo ["path" ],
441+ base_rev = None ,
442+ ref = "mybranch" ,
443+ commit = None ,
444+ ssh_key_file = None ,
445+ ssh_known_hosts_file = None ,
446+ shallow_clone = False , # Changed to False since shallow doesn't work with local repos
447+ )
448+
449+ # Check that files were checked out properly
450+ assert os .path .exists (os .path .join (destination , "mainfile" ))
451+ assert os .path .exists (os .path .join (destination , "branchfile" ))
452+
453+ # Check repo is on the right branch
454+ current_branch = subprocess .check_output (
455+ args = ["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ],
456+ cwd = destination ,
457+ universal_newlines = True ,
458+ ).strip ()
459+ assert current_branch == "mybranch"
460+
461+
462+ def test_collect_vcs_options_with_efficient_clone (
463+ run_task_mod ,
464+ ):
465+ """Test that shallow_clone option is collected properly."""
466+ args = Namespace (
467+ vcs_checkout = "/path/to/checkout" ,
468+ vcs_sparse_profile = None ,
469+ vcs_shallow_clone = True ,
470+ vcs_efficient_clone = True ,
471+ )
472+
473+ # Mock environment variables
474+ env_vars = {
475+ "VCS_REPOSITORY_TYPE" : "git" ,
476+ "VCS_HEAD_REPOSITORY" : "https://github.com/test/repo.git" ,
477+ "VCS_HEAD_REV" : "abc123" ,
478+ }
479+
480+ old_environ = os .environ .copy ()
481+ os .environ .update (env_vars )
482+
483+ try :
484+ options = run_task_mod .collect_vcs_options (args , "vcs" , "repository" )
485+ assert options ["shallow-clone" ]
486+ finally :
487+ os .environ .clear ()
488+ os .environ .update (old_environ )
489+
490+
423491def test_display_python_version_should_output_python_versions_title (
424492 run_task_mod , capsys
425493):
0 commit comments