Skip to content

Commit a7c0880

Browse files
committed
feat: add cache::state::attributes|ignore::Source::adjust_for_bare() to use non-worktree versions of source easily.
1 parent 3503f49 commit a7c0880

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

gix-worktree/src/stack/state/attributes.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ pub enum Source {
4545
WorktreeThenIdMapping,
4646
}
4747

48+
impl Source {
49+
/// Returns non-worktree variants of `self` if `is_bare` is true.
50+
pub fn adjust_for_bare(self, is_bare: bool) -> Self {
51+
if is_bare {
52+
Source::IdMapping
53+
} else {
54+
self
55+
}
56+
}
57+
}
58+
4859
/// Initialization
4960
impl Attributes {
5061
/// Create a new instance from an attribute match group that represents `globals`. It can more easily be created with

gix-worktree/src/stack/state/ignore.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ pub enum Source {
2525
WorktreeThenIdMappingIfNotSkipped,
2626
}
2727

28+
impl Source {
29+
/// Returns non-worktree variants of `self` if `is_bare` is true.
30+
pub fn adjust_for_bare(self, is_bare: bool) -> Self {
31+
if is_bare {
32+
Source::IdMapping
33+
} else {
34+
self
35+
}
36+
}
37+
}
38+
2839
/// Various aggregate numbers related [`Ignore`].
2940
#[derive(Default, Clone, Copy, Debug)]
3041
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

0 commit comments

Comments
 (0)