Skip to main content

vergen_lib/
config.rs

1// Copyright (c) 2022 vergen developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9use bon::Builder;
10
11// Common configuration structs
12
13/// git configuration for the `describe` output
14#[derive(Builder, Clone, Copy, Debug, Eq, PartialEq)]
15pub struct Describe {
16    /// Instead of using only the annotated tags, use any tag found in refs/tags namespace.
17    #[builder(default = false)]
18    tags: bool,
19    /// If the working tree has local modification "-dirty" is appended to it.
20    #[builder(default = false)]
21    dirty: bool,
22    /// Only consider tags matching the given glob pattern, excluding the "refs/tags/" prefix.
23    match_pattern: Option<&'static str>,
24}
25
26impl Describe {
27    /// Instead of using only the annotated tags, use any tag found in refs/tags namespace.
28    #[must_use]
29    pub fn tags(&self) -> bool {
30        self.tags
31    }
32
33    /// If the working tree has local modification "-dirty" is appended to it.
34    #[must_use]
35    pub fn dirty(&self) -> bool {
36        self.dirty
37    }
38
39    /// Only consider tags matching the given glob pattern, excluding the "refs/tags/" prefix.
40    #[must_use]
41    pub fn match_pattern(&self) -> &Option<&'static str> {
42        &self.match_pattern
43    }
44}
45
46/// git configuration for the `sha` output
47#[derive(Builder, Clone, Copy, Debug, Eq, PartialEq)]
48pub struct Sha {
49    /// Shortens the object name to a unique prefix
50    #[builder(default = false)]
51    short: bool,
52}
53
54impl Sha {
55    /// Shortens the object name to a unique prefix
56    #[must_use]
57    pub fn short(&self) -> bool {
58        self.short
59    }
60}
61
62/// git configuration for the `dirty` output
63#[derive(Builder, Clone, Copy, Debug, Eq, PartialEq)]
64pub struct Dirty {
65    /// Should we include/ignore untracked files in deciding whether the repository is dirty.
66    #[builder(default = false)]
67    include_untracked: bool,
68}
69
70impl Dirty {
71    /// Should we include/ignore untracked files in deciding whether the repository is dirty.
72    #[must_use]
73    pub fn include_untracked(&self) -> bool {
74        self.include_untracked
75    }
76}