Skip to content

Commit

Permalink
Use git CLI to fetch a repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed May 19, 2021
1 parent 67bc835 commit 5d229f5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 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,19 @@ 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")
.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 5d229f5

Please sign in to comment.