Skip to content

fix: assure submodules are skipped everywhere #1653

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

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion gix/src/object/tree/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn write_cursor<'repo>(cursor: &mut Cursor<'_, 'repo>) -> Result<Id<'repo>, writ
id: entry.oid,
source: err,
})?;
if !cursor.repo.has_object(entry.oid) {
if !entry.mode.is_commit() && !cursor.repo.has_object(entry.oid) {
return Err(write::Error::MissingObject {
filename: entry.filename.clone(),
kind: entry.mode.into(),
Expand Down
13 changes: 13 additions & 0 deletions gix/src/reference/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ pub mod head_tree_id {
}
}

///
pub mod head_tree {
/// The error returned by [`Repository::head_tree`(…)](crate::Repository::head_tree()).
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
HeadCommit(#[from] crate::reference::head_commit::Error),
#[error(transparent)]
CommitTree(#[from] crate::object::commit::Error),
}
}

///
pub mod find {
///
Expand Down
2 changes: 1 addition & 1 deletion gix/src/reference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod iter;
pub mod remote;

mod errors;
pub use errors::{edit, find, follow, head_commit, head_id, head_tree_id, peel};
pub use errors::{edit, find, follow, head_commit, head_id, head_tree, head_tree_id, peel};

use crate::ext::ObjectIdExt;

Expand Down
10 changes: 10 additions & 0 deletions gix/src/repository/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ impl crate::Repository {
Ok(self.head_commit()?.tree_id()?)
}

/// Return the tree object the `HEAD^{tree}` reference currently points to after peeling it fully,
/// following symbolic references and tags until a tree is found.
///
/// Note that this may fail for various reasons, most notably because the repository
/// is freshly initialized and doesn't have any commits yet. It could also fail if the
/// head does not point to a tree, unlikely but possible.
pub fn head_tree(&self) -> Result<crate::Tree<'_>, reference::head_tree::Error> {
Ok(self.head_commit()?.tree()?)
}

/// Find the reference with the given partial or full `name`, like `main`, `HEAD`, `heads/branch` or `origin/other`,
/// or return an error if it wasn't found.
///
Expand Down
14 changes: 14 additions & 0 deletions gix/tests/gix/repository/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ mod edit_tree {
Ok(())
}

#[test]
fn submodules_are_not_checked_for_existence() -> crate::Result {
let repo = crate::named_subrepo_opts("make_submodules.sh", "with-submodules", gix::open::Options::isolated())?
.with_object_memory();
let mut editor = repo.head_tree()?.edit()?;
let actual = editor.write()?;
assert_eq!(
actual,
repo.head_tree_id()?,
"Nothing changed, but it did validate the root tree that it would want to write"
);
Ok(())
}

#[test]
fn missing_objects_and_illformed_path_components_trigger_error() -> crate::Result {
let (repo, _tmp) = crate::repo_rw("make_packed_and_loose.sh")?;
Expand Down
Loading