Skip to content

Commit

Permalink
Merge pull request #130 from ehuss/cli-fetch
Browse files Browse the repository at this point in the history
Use git CLI to fetch a repo.
  • Loading branch information
spastorino committed Oct 5, 2021
2 parents e80c73f + 0f93319 commit 63a18d8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::env;
use std::path::Path;

use chrono::{TimeZone, Utc};
use failure::{bail, Error};
use failure::{bail, Error, ResultExt};
use git2::build::RepoBuilder;
use git2::{Commit as Git2Commit, Repository};
use log::debug;
Expand All @@ -34,13 +34,21 @@ fn lookup_rev<'rev>(repo: &'rev Repository, rev: &str) -> Result<Git2Commit<'rev

fn get_repo() -> Result<Repository, Error> {
fn open(repo: &Path) -> Result<Repository, Error> {
eprintln!("refreshing repository at {:?}", repo);
// This uses the CLI because libgit2 is quite slow to fetch a large repository.
let status = std::process::Command::new("git")
.arg("fetch")
.arg(RUST_SRC_URL)
.current_dir(repo)
.status()
.context(format!(
"expected `git` command-line executable to be installed"
))?;
if !status.success() {
bail!("git fetch failed exit status {}", status);
}
eprintln!("opening existing repository at {:?}", repo);
let repo = Repository::open(repo)?;
{
eprintln!("refreshing repository");
let mut remote = repo.remote_anonymous(RUST_SRC_URL)?;
remote.fetch(&["master"], None, None)?;
}
Ok(repo)
}

Expand Down

0 comments on commit 63a18d8

Please sign in to comment.