MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / clone_github_template

Function clone_github_template

crates/cli/src/subcommands/init.rs:956–1009  ·  view source on GitHub ↗
(repo_input: &str, target: &Path, is_server_only: bool)

Source from the content-addressed store, hash-verified

954}
955
956fn clone_github_template(repo_input: &str, target: &Path, is_server_only: bool) -> anyhow::Result<()> {
957 let is_git_url = |s: &str| {
958 s.starts_with("git@") || s.starts_with("ssh://") || s.starts_with("http://") || s.starts_with("https://")
959 };
960
961 let repo_url = if is_git_url(repo_input) {
962 repo_input.to_string()
963 } else if repo_input.contains('/') {
964 format!("https://github.com/{}", repo_input)
965 } else {
966 anyhow::bail!("Invalid repository format. Use 'owner/repo' or full git clone URL");
967 };
968
969 println!(" Cloning from {}...", repo_url);
970
971 let temp_dir = tempfile::tempdir()?;
972
973 let mut builder = git2::build::RepoBuilder::new();
974
975 let mut fetch_options = git2::FetchOptions::new();
976 let mut callbacks = git2::RemoteCallbacks::new();
977
978 callbacks.credentials(|_url, username_from_url, allowed_types| {
979 if allowed_types.contains(git2::CredentialType::SSH_KEY)
980 && let Some(username) = username_from_url
981 {
982 return git2::Cred::ssh_key_from_agent(username);
983 }
984 if allowed_types.contains(git2::CredentialType::USER_PASS_PLAINTEXT) {
985 return git2::Cred::userpass_plaintext("", "");
986 }
987 if allowed_types.contains(git2::CredentialType::DEFAULT) {
988 return git2::Cred::default();
989 }
990 Err(git2::Error::from_str("no auth method available"))
991 });
992
993 fetch_options.remote_callbacks(callbacks);
994 builder.fetch_options(fetch_options);
995
996 builder
997 .clone(&repo_url, temp_dir.path())
998 .context("Failed to clone repository")?;
999
1000 if is_server_only {
1001 let server_subdir = temp_dir.path().join("spacetimedb");
1002 let server_subdir_target = target.join("spacetimedb");
1003 copy_dir_all(&server_subdir, &server_subdir_target)?;
1004 } else {
1005 copy_dir_all(temp_dir.path(), target)?;
1006 }
1007
1008 Ok(())
1009}
1010
1011fn copy_dir_all(src: &Path, dst: &Path) -> anyhow::Result<()> {
1012 fs::create_dir_all(dst)?;

Callers 1

init_github_templateFunction · 0.85

Calls 10

from_strFunction · 0.85
copy_dir_allFunction · 0.85
joinMethod · 0.80
newFunction · 0.50
ErrFunction · 0.50
OkFunction · 0.50
to_stringMethod · 0.45
containsMethod · 0.45
cloneMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…