Skip to content

Commit

Permalink
Merge pull request #1653 from GitoxideLabs/merge
Browse files Browse the repository at this point in the history
fix: assure submodules are skipped everywhere
  • Loading branch information
Byron authored Nov 6, 2024
2 parents a876533 + 4079519 commit 697a632
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
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

0 comments on commit 697a632

Please sign in to comment.