MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / git_clone_all

Function git_clone_all

flow-quickstart/src/git.rs:253–298  ·  view source on GitHub ↗
(project_dir: &Path, args: GitConfig)

Source from the content-addressed store, hash-verified

251}
252
253fn git_clone_all(project_dir: &Path, args: GitConfig) -> Result<String> {
254 let mut builder = RepoBuilder::new();
255 if let GitReference::Branch(branch_name) = &args.branch {
256 builder.branch(branch_name.as_str());
257 }
258
259 let mut fo = FetchOptions::new();
260 match args.kind {
261 RepoKind::LocalFolder => {}
262 RepoKind::RemoteHttp | RepoKind::RemoteHttps => {
263 let mut proxy = ProxyOptions::new();
264 proxy.auto();
265 fo.proxy_options(proxy);
266 }
267 RepoKind::RemoteSsh => {
268 let callbacks = git_ssh_credentials_callback(args.identity)?;
269 fo.remote_callbacks(callbacks);
270 }
271 RepoKind::Invalid => {
272 unreachable!()
273 }
274 }
275 builder.fetch_options(fo);
276
277 match builder.clone(args.remote.as_ref(), project_dir) {
278 Ok(repo) => {
279 let branch = get_branch_name_repo(&repo)?;
280 init_all_submodules(&repo)?;
281 Ok(branch)
282 }
283 Err(e) => {
284 if e.code() != ErrorCode::NotFound {
285 return Err(e.into());
286 }
287
288 let path = Path::new(&*args.remote);
289 if !path.exists() || !path.is_dir() {
290 return Err(e.into());
291 }
292
293 warn!("Template does not seem to be a git repository, using as a plain folder");
294 copy_dir_all(path, project_dir)?;
295 Ok("".to_string())
296 }
297 }
298}
299
300fn remove_history(project_dir: &Path, attempt: Option<u8>) -> Result<()> {
301 let git_dir = project_dir.join(".git");

Callers 1

createFunction · 0.85

Calls 6

get_branch_name_repoFunction · 0.85
init_all_submodulesFunction · 0.85
copy_dir_allFunction · 0.85
as_refMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected