Skip to content

Commit

Permalink
feat: gix index entries now works on bare repositories.
Browse files Browse the repository at this point in the history
It creates the index in-memory if needed based on the current HEAD tree.

This is useful when inspecting attributes and ignore information.
  • Loading branch information
Byron committed May 24, 2023
1 parent 596ff7a commit 042f2e1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gitoxide-core/src/repository/index/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Attributes {
}

pub(crate) mod function {
use crate::repository::attributes::query::index_on_demand;
use crate::repository::index::entries::{Attributes, Options};
use gix::odb::FindExt;
use std::borrow::Cow;
Expand All @@ -31,20 +32,28 @@ pub(crate) mod function {
}: Options,
) -> anyhow::Result<()> {
use crate::OutputFormat::*;
let index = repo.index()?;
let index = index_on_demand(&repo)?;
let mut cache = attributes
.map(|attrs| {
repo.attributes(
&index,
match attrs {
Attributes::WorktreeAndIndex => {
gix::worktree::cache::state::attributes::Source::WorktreeThenIdMapping
if repo.is_bare() {
gix::worktree::cache::state::attributes::Source::IdMapping
} else {
gix::worktree::cache::state::attributes::Source::WorktreeThenIdMapping
}
}
Attributes::Index => gix::worktree::cache::state::attributes::Source::IdMapping,
},
match attrs {
Attributes::WorktreeAndIndex => {
gix::worktree::cache::state::ignore::Source::WorktreeThenIdMappingIfNotSkipped
if repo.is_bare() {
gix::worktree::cache::state::ignore::Source::IdMapping
} else {
gix::worktree::cache::state::ignore::Source::WorktreeThenIdMappingIfNotSkipped
}
}
Attributes::Index => gix::worktree::cache::state::ignore::Source::IdMapping,
},
Expand Down

0 comments on commit 042f2e1

Please sign in to comment.