@@ -59,23 +59,33 @@ impl Git {
5959 // Create a temporary directory for the local repository
6060 let temp_dir = tempfile:: tempdir ( ) ?;
6161 let root_path = temp_dir. path ( ) ;
62- let clone_path = root_path. join ( "cloned-repo" ) ;
6362
6463 let source_repo_url = format ! ( "https://github.com/{source_repo}.git" ) ;
6564
66- // Then do a partial clone of a single commit, without a checkout, and without and blob or
67- // trees
68- tracing:: debug!( "Cloning commit" ) ;
6965 run_command (
7066 tokio:: process:: Command :: new ( & self . git )
7167 . kill_on_drop ( true )
7268 . current_dir ( root_path)
73- . arg ( "clone" )
69+ . arg ( "init" )
70+ . arg ( "--bare" ) ,
71+ )
72+ . await
73+ . context ( "Cannot perform git init" ) ?;
74+
75+ // It **should** be much faster to do a partial clone than a fetch with depth=1.
76+ // However, on the production server, the partial clone of rust-lang/rust seems to choke :(
77+ // So we use the fetch as an alternative.
78+ tracing:: debug!( "Fetching commit" ) ;
79+ run_command (
80+ tokio:: process:: Command :: new ( & self . git )
81+ . kill_on_drop ( true )
82+ . current_dir ( root_path)
83+ . arg ( "fetch" )
7484 . arg ( "--depth=1" )
75- . arg ( "--no-checkout" )
76- . arg ( "--filter=tree:0" )
85+ // Note: using --filter=tree:0 makes the fetch much faster, but the resulting push
86+ // becomes MUCH slower :(
7787 . arg ( source_repo_url)
78- . arg ( & clone_path ) ,
88+ . arg ( commit . as_ref ( ) ) ,
7989 )
8090 . await
8191 . context ( "Cannot perform git clone" ) ?;
@@ -98,13 +108,11 @@ impl Git {
98108 run_command (
99109 tokio:: process:: Command :: new ( & self . git )
100110 . kill_on_drop ( true )
101- . current_dir ( & clone_path)
102- . env ( "GIT_TRACE" , "1" )
111+ . current_dir ( root_path)
103112 // Do not store the token on disk
104- // .arg("-c")
105- // .arg("credential.helper=")
113+ . arg ( "-c" )
114+ . arg ( "credential.helper=" )
106115 . arg ( "push" )
107- . arg ( "-v" )
108116 . arg ( & target_repo_url)
109117 . arg ( refspec) ,
110118 )
0 commit comments