diff --git a/src/git.rs b/src/git.rs index f5dda5f..6244d5d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -26,6 +26,13 @@ pub enum GitCommand { #[arg()] /// Name of the repo name: String + }, + + /// Clone a repo from the remote + Clone { + #[arg()] + /// Name of the repo + name: String } } @@ -72,11 +79,13 @@ pub async fn handle_git(cmd: &GitCommand) { eprintln!( "{}", - String::from_utf8(ls.stdout).expect("Failed to rm repo.") + String::from_utf8(ls.stdout).expect("Failed to list repos.") ); } GitCommand::Add { name } => { add_remote_to_repo(name.to_string()); } + + GitCommand::Clone { name } => { clone_repo(name.to_string()); } } } @@ -86,12 +95,27 @@ fn add_remote_to_repo(name: String) { .arg("remote") .arg("add") .arg("origin") - .arg("git@breadpi.local:/home/git/store/".to_owned() + &name + ".git") + .arg("git@breadpi:/home/git/store/".to_owned() + &name + ".git") .output().expect("Could not add remote"); eprintln!( "{}", - String::from_utf8(cmd.stdout).expect("Failed to rm git repo.") + String::from_utf8(cmd.stdout).expect("Failed to add git remote.") ); - println!("Added remote origin git@breadpi.local:/home/git/store/{name}.git"); + println!("Added remote origin git@breadpi:/home/git/store/{name}.git"); +} + + +fn clone_repo(name: String) { + let cmd = Command::new("git") + .arg("clone") + .arg("git@breadpi:/home/git/store/".to_owned() + &name + ".git") + .output().expect("Could not clone repo"); + + eprintln!( + "{}", + String::from_utf8(cmd.stdout).expect("Failed to clone repo.") + ); + + println!("Clone repo git@breadpi:/home/git/store/{name}.git to local folder."); } \ No newline at end of file