Skip to content

Commit

Permalink
Do not fail if a branch has other commits than the lock file (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimush authored Oct 31, 2023
1 parent a03b024 commit d2a6918
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn lock(
.resolve(
&dependency.coordinate,
&dependency.specification,
None,
&dependency.name,
)
.map_err(FetchError::Resolver)?;
Expand Down Expand Up @@ -194,6 +195,7 @@ mod tests {
&self,
coordinate: &Coordinate,
specification: &RevisionSpecification,
_: Option<&str>,
_: &DependencyName,
) -> anyhow::Result<ResolvedModule> {
Ok(self
Expand Down
13 changes: 11 additions & 2 deletions src/resolver/git.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
cache::{ProtofetchGitCache, RepositoryCache},
model::protofetch::{Coordinate, DependencyName, RevisionSpecification},
model::protofetch::{Coordinate, DependencyName, Revision, RevisionSpecification},
};

use super::{ModuleResolver, ResolvedModule};
Expand All @@ -10,10 +10,19 @@ impl ModuleResolver for ProtofetchGitCache {
&self,
coordinate: &Coordinate,
specification: &RevisionSpecification,
commit_hash: Option<&str>,
name: &DependencyName,
) -> anyhow::Result<ResolvedModule> {
let repository = self.clone_or_update(coordinate)?;
let commit_hash = repository.resolve_commit_hash(specification)?;
let commit_hash = if specification.revision == Revision::Arbitrary {
if let Some(commit_hash) = commit_hash {
commit_hash.to_owned()
} else {
repository.resolve_commit_hash(specification)?
}
} else {
repository.resolve_commit_hash(specification)?
};
let descriptor = repository.extract_descriptor(name, &commit_hash)?;
Ok(ResolvedModule {
commit_hash,
Expand Down
22 changes: 17 additions & 5 deletions src/resolver/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ where
&self,
coordinate: &Coordinate,
specification: &RevisionSpecification,
commit_hash: Option<&str>,
name: &DependencyName,
) -> anyhow::Result<ResolvedModule> {
let dependency = self.lock_file.dependencies.iter().find(|dependency| {
Expand All @@ -40,10 +41,20 @@ where
"Dependency {} {} found in the lock file with commit {}",
coordinate, specification, dependency.commit_hash
);
let commit_hash = dependency.commit_hash.clone();
let resolved = self.inner.resolve(coordinate, specification, name)?;
if resolved.commit_hash != commit_hash {
bail!("Commit hash of {} {} changed: the lock file specifies {}, but the actual commit hash is {}", coordinate, specification, commit_hash, resolved.commit_hash);
let resolved = self.inner.resolve(
coordinate,
specification,
commit_hash.or(Some(&dependency.commit_hash)),
name,
)?;
if resolved.commit_hash != dependency.commit_hash {
bail!(
"Commit hash of {} {} changed: the lock file specifies {}, but the actual commit hash is {}",
coordinate,
specification,
dependency.commit_hash,
resolved.commit_hash
);
}
Ok(resolved)
}
Expand All @@ -59,7 +70,8 @@ where
"Dependency {} {} not found in the lock file",
coordinate, specification
);
self.inner.resolve(coordinate, specification, name)
self.inner
.resolve(coordinate, specification, commit_hash, name)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub trait ModuleResolver {
&self,
coordinate: &Coordinate,
specification: &RevisionSpecification,
commit_hash: Option<&str>,
name: &DependencyName,
) -> anyhow::Result<ResolvedModule>;
}
Expand All @@ -28,8 +29,9 @@ where
&self,
coordinate: &Coordinate,
specification: &RevisionSpecification,
commit_hash: Option<&str>,
name: &DependencyName,
) -> anyhow::Result<ResolvedModule> {
T::resolve(self, coordinate, specification, name)
T::resolve(self, coordinate, specification, commit_hash, name)
}
}

0 comments on commit d2a6918

Please sign in to comment.