git_clone_canonical/
git.rs1use crate::{Error, Result, Url};
2use std::path::Path;
3use std::process::Command;
4
5pub fn clone(parentdir: &Path, url: Url) -> Result<()> {
6 let urlstr = url.as_str();
7 log::info!("cloning {:?}", &urlstr);
8 run(parentdir, "git", &["clone", urlstr])
9}
10
11pub fn fetch(repodir: &Path, url: Url) -> Result<()> {
12 let urlstr = url.as_str();
13 log::info!("fetching {:?}", &urlstr);
14 run(repodir, "git", &["fetch", urlstr])
15}
16
17fn run(cwd: &Path, exec: &str, args: &[&str]) -> Result<()> {
18 let mut cmd = Command::new(exec);
19 cmd.current_dir(cwd);
20 cmd.args(args);
21 let cmdstr = format!("{:?}", &cmd);
22 log::debug!("running {}", &cmdstr);
23 let status = cmd.status()?;
24 log::debug!("exit status {:?}", &status);
25 if status.success() {
26 Ok(())
27 } else {
28 Err(Error::ChildExit(cmdstr, status.code()))
29 }
30}