Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git CLI to fetch a repo. #130

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to use something like the old repo.remote_anonymous(RUST_SRC_URL). E.g., if I run git fetch in my rust-lang/rust clone, it only fetches my fork, which doesn't have the latest changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I normally point it at a repo where origin is rust-lang/rust, but it makes sense to use the correct remote. I don't think it can use an anonymous remote (since that is in memory only), but I added the URL to the fetch line which should do the right thing.

.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