Skip to content

Commit 3df2fbb

Browse files
CopilotByron
andcommitted
Add documentation with example for optional path feature
Co-authored-by: Byron <[email protected]>
1 parent d299d37 commit 3df2fbb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

gix-config-value/src/types.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ pub struct Boolean(pub bool);
4141
/// Any value that can be interpreted as a path to a resource on disk.
4242
///
4343
/// Git represents file paths as byte arrays, modeled here as owned or borrowed byte sequences.
44+
///
45+
/// ## Optional Paths
46+
///
47+
/// Paths can be marked as optional by prefixing them with `:(optional)` in the configuration.
48+
/// This indicates that it's acceptable if the file doesn't exist, which is useful for
49+
/// configuration values like `blame.ignorerevsfile` that may only exist in some repositories.
50+
///
51+
/// ```
52+
/// use std::borrow::Cow;
53+
/// use gix_config_value::Path;
54+
/// use bstr::ByteSlice;
55+
///
56+
/// // Regular path - file is expected to exist
57+
/// let path = Path::from(Cow::Borrowed(b"/etc/gitconfig".as_bstr()));
58+
/// assert!(!path.is_optional());
59+
///
60+
/// // Optional path - it's okay if the file doesn't exist
61+
/// let path = Path::from(Cow::Borrowed(b":(optional)~/.gitignore".as_bstr()));
62+
/// assert!(path.is_optional());
63+
/// assert_eq!(path.value.as_ref(), b"~/.gitignore"); // prefix is stripped
64+
/// ```
4465
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
4566
pub struct Path<'a> {
4667
/// The path string, un-interpolated

0 commit comments

Comments
 (0)