Skip to content

Commit cd6a2f7

Browse files
committed
Use git CLI to fetch a repo.
1 parent 67bc835 commit cd6a2f7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: src/git.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::env;
77
use std::path::Path;
88

99
use chrono::{TimeZone, Utc};
10-
use failure::{bail, Error};
10+
use failure::{bail, Error, ResultExt};
1111
use git2::build::RepoBuilder;
1212
use git2::{Commit as Git2Commit, Repository};
1313
use log::debug;
@@ -34,13 +34,20 @@ fn lookup_rev<'rev>(repo: &'rev Repository, rev: &str) -> Result<Git2Commit<'rev
3434

3535
fn get_repo() -> Result<Repository, Error> {
3636
fn open(repo: &Path) -> Result<Repository, Error> {
37+
eprintln!("refreshing repository at {:?}", repo);
38+
// This uses the CLI because libgit2 is quite slow to fetch a large repository.
39+
let status = std::process::Command::new("git")
40+
.arg("fetch")
41+
.current_dir(repo)
42+
.status()
43+
.context(format!(
44+
"expected `git` command-line executable to be installed"
45+
))?;
46+
if !status.success() {
47+
bail!("git fetch failed exit status {}", status);
48+
}
3749
eprintln!("opening existing repository at {:?}", repo);
3850
let repo = Repository::open(repo)?;
39-
{
40-
eprintln!("refreshing repository");
41-
let mut remote = repo.remote_anonymous(RUST_SRC_URL)?;
42-
remote.fetch(&["master"], None, None)?;
43-
}
4451
Ok(repo)
4552
}
4653

0 commit comments

Comments
 (0)