pub struct GitContext {
pub branch: Option<String>,
pub head: Option<String>,
pub working_tree: String,
pub commits: Vec<CommitReference>,
}Expand description
The head this answer was compiled against. A compiled context is only true of one tree, and these three fields plus the index fingerprint are what say which.
branch and head are optional because a checkout can legitimately have neither — a
detached head, or a tree that is not a git repository at all — and the absence is carried
rather than faked. working_tree is not optional, because there is always something to
say: when git cannot be reached it carries unavailable: <reason> instead of a status,
so a reader is never left unable to tell “clean” from “not asked”.
commits is derived from the selected entries’ own records and never from a log walk.
That is the difference between “the commits this work says it produced” and “what
happened to be committed recently”, and only the first is context.
use majordomus_cli::devcontext::GitContext;
use serde_json::json;
// a tree the compiler could read
let known: GitContext = serde_json::from_value(json!({
"branch": "master",
"head": "cd04012f1b1dc21fd493e2be14938ffdfaccc8fa",
"working_tree": "clean",
})).unwrap();
assert_eq!(known.branch.as_deref(), Some("master"));
assert!(known.commits.is_empty(), "no selected record named a commit");
// and one it could not: the status field still says something a reader can act on
let unknown: GitContext = serde_json::from_value(json!({
"working_tree": "unavailable: not a git repository",
})).unwrap();
assert!(unknown.head.is_none() && unknown.branch.is_none());
assert!(
unknown.working_tree.starts_with("unavailable: "),
"never silently indistinguishable from clean",
);Fields§
§branch: Option<String>The branch, when the checkout is on one.
head: Option<String>The head commit.
working_tree: Stringclean, dirty, or what git said.
commits: Vec<CommitReference>Commits the selected entries name as their own evidence, newest record first. Derived from the layer’s records, never from a log walk.
Trait Implementations§
Source§impl Clone for GitContext
impl Clone for GitContext
Source§fn clone(&self) -> GitContext
fn clone(&self) -> GitContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GitContext
impl Debug for GitContext
Source§impl<'de> Deserialize<'de> for GitContext
impl<'de> Deserialize<'de> for GitContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for GitContext
Source§impl JsonSchema for GitContext
impl JsonSchema for GitContext
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for GitContext
impl PartialEq for GitContext
Source§fn eq(&self, other: &GitContext) -> bool
fn eq(&self, other: &GitContext) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for GitContext
impl Serialize for GitContext
impl StructuralPartialEq for GitContext
Auto Trait Implementations§
impl Freeze for GitContext
impl RefUnwindSafe for GitContext
impl Send for GitContext
impl Sync for GitContext
impl Unpin for GitContext
impl UnsafeUnpin for GitContext
impl UnwindSafe for GitContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.