use worktrunk::git::LineDiff;
#[derive(serde::Serialize, Clone, Default, Debug)]
pub struct CommitDetails {
pub timestamp: i64,
pub commit_message: String,
}
#[derive(serde::Serialize, Default, Copy, Clone, Debug)]
pub struct AheadBehind {
pub ahead: usize,
pub behind: usize,
}
#[derive(serde::Serialize, Default, Copy, Clone, Debug)]
pub struct BranchDiffTotals {
#[serde(rename = "branch_diff")]
pub diff: LineDiff,
}
#[derive(serde::Serialize, Default, Clone, Debug)]
pub struct UpstreamStatus {
#[serde(rename = "upstream_remote")]
pub(crate) remote: Option<String>,
#[serde(rename = "upstream_ahead")]
pub(crate) ahead: usize,
#[serde(rename = "upstream_behind")]
pub(crate) behind: usize,
}
pub struct ActiveUpstream<'a> {
pub remote: &'a str,
pub ahead: usize,
pub behind: usize,
}
impl UpstreamStatus {
pub fn active(&self) -> Option<ActiveUpstream<'_>> {
self.remote.as_deref().map(|remote| ActiveUpstream {
remote,
ahead: self.ahead,
behind: self.behind,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_upstream_status_active_with_remote() {
let status = UpstreamStatus {
remote: Some("origin".to_string()),
ahead: 3,
behind: 2,
};
let active = status.active().unwrap();
assert_eq!(active.remote, "origin");
assert_eq!(active.ahead, 3);
assert_eq!(active.behind, 2);
}
#[test]
fn test_upstream_status_active_no_remote() {
let status = UpstreamStatus {
remote: None,
ahead: 0,
behind: 0,
};
assert!(status.active().is_none());
}
}