Skip to content

various improvements #1769

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
Jan 15, 2025
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
14 changes: 11 additions & 3 deletions gix/src/status/index_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,21 @@ mod submodule_status {
mode: Submodule,
) -> Result<Self, crate::submodule::modules::Error> {
let local_repo = repo.to_thread_local();
let submodule_paths = match local_repo.submodules()? {
Some(sm) => {
let submodule_paths = match local_repo.submodules() {
Ok(Some(sm)) => {
let mut v: Vec<_> = sm.filter_map(|sm| sm.path().ok().map(Cow::into_owned)).collect();
v.sort();
v
}
None => Vec::new(),
Ok(None) => Vec::new(),
Err(crate::submodule::modules::Error::FindHeadCommit(
crate::reference::head_commit::Error::PeelToCommit(
crate::head::peel::to_commit::Error::PeelToObject(
crate::head::peel::to_object::Error::Unborn { .. },
),
),
)) => Vec::new(),
Err(err) => return Err(err),
};
Ok(Self {
mode,
Expand Down
12 changes: 11 additions & 1 deletion gix/src/status/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ where

let obtain_tree_id = || -> Result<Option<gix_hash::ObjectId>, crate::status::into_iter::Error> {
Ok(match self.head_tree {
Some(None) => Some(self.repo.head_tree_id()?.into()),
Some(None) => match self.repo.head_tree_id() {
Ok(id) => Some(id.into()),
Err(crate::reference::head_tree_id::Error::HeadCommit(
crate::reference::head_commit::Error::PeelToCommit(
crate::head::peel::to_commit::Error::PeelToObject(
crate::head::peel::to_object::Error::Unborn { .. },
),
),
)) => None,
Err(err) => return Err(err.into()),
},
Some(Some(tree_id)) => Some(tree_id),
None => None,
})
Expand Down
Binary file modified gix/tests/fixtures/generated-archives/make_status_repos.tar
Binary file not shown.
5 changes: 5 additions & 0 deletions gix/tests/fixtures/make_status_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ git init racy-git

echo ho >file && git add file
echo ha >file
)

git init untracked-unborn
(cd untracked-unborn
touch untracked
)
30 changes: 30 additions & 0 deletions gix/tests/gix/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ mod into_iter {
Ok(())
}

#[test]
fn untracked_unborn() -> crate::Result {
let repo = repo("untracked-unborn")?;
let mut status = repo.status(gix::progress::Discard)?.into_iter(None)?;
let mut items: Vec<_> = status.by_ref().filter_map(Result::ok).collect();
items.sort_by(|a, b| a.location().cmp(b.location()));
insta::assert_debug_snapshot!(items, @r#"
[
IndexWorktree(
DirectoryContents {
entry: Entry {
rela_path: "untracked",
status: Untracked,
property: None,
disk_kind: Some(
File,
),
index_kind: None,
pathspec_match: Some(
Always,
),
},
collapsed_directory_status: None,
},
),
]
"#);
Ok(())
}

#[test]
fn error_during_tree_traversal_causes_failure() -> crate::Result {
let repo = repo("untracked-only")?;
Expand Down
Loading