Skip to content

Commit

Permalink
make sure that submodule hashes aren't attached as the parent repo is…
Browse files Browse the repository at this point in the history
… the wrong one here.
  • Loading branch information
Byron committed Aug 21, 2023
1 parent e0d9b09 commit c96f26b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions gix/src/submodule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use gix_odb::FindExt;
pub use gix_submodule::*;

use crate::{bstr::BStr, ext::ObjectIdExt, repository::IndexPersistedOrInMemory, Id, Repository, Submodule};
use crate::{bstr::BStr, repository::IndexPersistedOrInMemory, Repository, Submodule};

pub(crate) type ModulesFileStorage = gix_features::threading::OwnShared<gix_fs::SharedFileSnapshotMut<File>>;
/// A lazily loaded and auto-updated worktree index.
Expand Down Expand Up @@ -164,29 +164,25 @@ impl<'repo> Submodule<'repo> {
/// If `None`, but `Some()` when calling [`Self::head_id()`], then the submodule was just deleted but the change
/// wasn't yet committed.
/// If `Some()`, but `None` when calling [`Self::head_id()`], then the submodule was just added without having committed the change.
pub fn index_id(&self) -> Result<Option<Id<'repo>>, index_id::Error> {
pub fn index_id(&self) -> Result<Option<gix_hash::ObjectId>, index_id::Error> {
let path = self.path()?;
Ok(self
.state
.index()?
.entry_by_path(&path)
.map(|entry| entry.id.attach(self.state.repo)))
Ok(self.state.index()?.entry_by_path(&path).map(|entry| entry.id))
}

/// Return the object id of the submodule as stored in `HEAD^{tree}` of the superproject, or `None` if it wasn't yet committed.
///
/// If `Some()`, but `None` when calling [`Self::index_id()`], then the submodule was just deleted but the change
/// wasn't yet committed.
/// If `None`, but `Some()` when calling [`Self::index_id()`], then the submodule was just added without having committed the change.
pub fn head_id(&self) -> Result<Option<Id<'repo>>, head_id::Error> {
pub fn head_id(&self) -> Result<Option<gix_hash::ObjectId>, head_id::Error> {
let path = self.path()?;
Ok(self
.state
.repo
.head_commit()?
.tree()?
.peel_to_entry_by_path(gix_path::from_bstr(path.as_ref()))?
.map(|entry| entry.id()))
.map(|entry| entry.inner.oid))
}

/// Return the path at which the repository of the submodule should be located.
Expand Down
6 changes: 3 additions & 3 deletions gix/tests/repository/submodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod modules_file {
}

mod submodules {
use gix::{bstr::BString, Id};
use gix::bstr::BString;

use crate::{submodule::repo, util::hex_to_id};

Expand All @@ -72,8 +72,8 @@ mod submodules {
.map(|sm| (
sm.name().to_owned(),
sm.path().expect("valid path").into_owned(),
sm.head_id().expect("valid").map(Id::detach),
sm.index_id().expect("valid").map(Id::detach),
sm.head_id().expect("valid"),
sm.index_id().expect("valid"),
sm.is_active().expect("no config error")
))
.collect::<Vec<_>>(),
Expand Down

0 comments on commit c96f26b

Please sign in to comment.