Skip to content

Commit 697a632

Browse files
authored
Merge pull request #1653 from GitoxideLabs/merge
fix: assure submodules are skipped everywhere
2 parents a876533 + 4079519 commit 697a632

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

gix/src/object/tree/editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn write_cursor<'repo>(cursor: &mut Cursor<'_, 'repo>) -> Result<Id<'repo>, writ
263263
id: entry.oid,
264264
source: err,
265265
})?;
266-
if !cursor.repo.has_object(entry.oid) {
266+
if !entry.mode.is_commit() && !cursor.repo.has_object(entry.oid) {
267267
return Err(write::Error::MissingObject {
268268
filename: entry.filename.clone(),
269269
kind: entry.mode.into(),

gix/src/reference/errors.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ pub mod head_tree_id {
106106
}
107107
}
108108

109+
///
110+
pub mod head_tree {
111+
/// The error returned by [`Repository::head_tree`(…)](crate::Repository::head_tree()).
112+
#[derive(Debug, thiserror::Error)]
113+
#[allow(missing_docs)]
114+
pub enum Error {
115+
#[error(transparent)]
116+
HeadCommit(#[from] crate::reference::head_commit::Error),
117+
#[error(transparent)]
118+
CommitTree(#[from] crate::object::commit::Error),
119+
}
120+
}
121+
109122
///
110123
pub mod find {
111124
///

gix/src/reference/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod iter;
1010
pub mod remote;
1111

1212
mod errors;
13-
pub use errors::{edit, find, follow, head_commit, head_id, head_tree_id, peel};
13+
pub use errors::{edit, find, follow, head_commit, head_id, head_tree, head_tree_id, peel};
1414

1515
use crate::ext::ObjectIdExt;
1616

gix/src/repository/reference.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ impl crate::Repository {
215215
Ok(self.head_commit()?.tree_id()?)
216216
}
217217

218+
/// Return the tree object the `HEAD^{tree}` reference currently points to after peeling it fully,
219+
/// following symbolic references and tags until a tree is found.
220+
///
221+
/// Note that this may fail for various reasons, most notably because the repository
222+
/// is freshly initialized and doesn't have any commits yet. It could also fail if the
223+
/// head does not point to a tree, unlikely but possible.
224+
pub fn head_tree(&self) -> Result<crate::Tree<'_>, reference::head_tree::Error> {
225+
Ok(self.head_commit()?.tree()?)
226+
}
227+
218228
/// Find the reference with the given partial or full `name`, like `main`, `HEAD`, `heads/branch` or `origin/other`,
219229
/// or return an error if it wasn't found.
220230
///

gix/tests/gix/repository/object.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ mod edit_tree {
118118
Ok(())
119119
}
120120

121+
#[test]
122+
fn submodules_are_not_checked_for_existence() -> crate::Result {
123+
let repo = crate::named_subrepo_opts("make_submodules.sh", "with-submodules", gix::open::Options::isolated())?
124+
.with_object_memory();
125+
let mut editor = repo.head_tree()?.edit()?;
126+
let actual = editor.write()?;
127+
assert_eq!(
128+
actual,
129+
repo.head_tree_id()?,
130+
"Nothing changed, but it did validate the root tree that it would want to write"
131+
);
132+
Ok(())
133+
}
134+
121135
#[test]
122136
fn missing_objects_and_illformed_path_components_trigger_error() -> crate::Result {
123137
let (repo, _tmp) = crate::repo_rw("make_packed_and_loose.sh")?;

0 commit comments

Comments
 (0)