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

git: Bail out if the url is sparse #167

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions examples/list_recent_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ fn fetch_crate(name: &str, sparse_index: &SparseIndex) -> Result<Option<Crate>,
}

fn names(name: &str) -> Result<impl Iterator<Item = String>, Box<dyn Error>> {
Ok(Names::new(name)
.ok_or_else(|| "Too many hyphens in crate name")?
.take(3))
Ok(Names::new(name).ok_or("Too many hyphens in crate name")?.take(3))
}

/// Create a request to the sparse `index` and parse the response with the side-effect of yielding
Expand Down
7 changes: 5 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ pub use toml::de::Error as TomlDeError;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("\"gix\" crate failed. If problems persist, consider deleting `~/.cargo/registry/index/github.com-1ecc6299db9ec823/`")]
// ~/.cargo/registry/index/github.com-1ecc6299db9ec823/
#[error("\"gix\" crate failed. If problems persist, consider deleting `TODO`")]
#[cfg(feature = "git")]
Git(#[from] GixError),
Git(#[from] GixError), // String
#[error("{0}")]
Url(String),
#[error("GitIndex cannot take sparse URL `{0}`, use SparseIndex")]
UrlIsSparse(String),
#[error("Could not obtain the most recent head commit in repo at {}. Tried {}, had {} available", repo_path.display(), refs_tried.join(", "), refs_available.join(", "))]
MissingHead {
/// The references we tried to get commits for.
Expand Down
6 changes: 5 additions & 1 deletion src/git/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Change {
#[inline]
#[must_use]
pub fn crate_name(&self) -> &str {
&*self.crate_name
&self.crate_name
}

/// Timestamp in the crates.io index repository, which may be publication or modification date
Expand Down Expand Up @@ -155,6 +155,10 @@ impl GitIndex {
}

fn from_path_and_url(path: PathBuf, url: String, mode: Mode) -> Result<Option<Self>, Error> {
if url.starts_with("sparse+http") {
return Err(Error::UrlIsSparse(url.to_owned()));
}

let open_with_complete_config = gix::open::Options::default().permissions(gix::open::Permissions {
config: gix::open::permissions::Config {
// Be sure to get all configuration, some of which is only known by the git binary.
Expand Down
Loading