git/
status.rs

1/// Represents the type of change of a diff entry
2#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3#[allow(clippy::exhaustive_enums)]
4pub enum Status {
5	/// Entry does not exist in old version
6	Added,
7	/// Entry does not exist in new version
8	Deleted,
9	/// Entry content changed between old and new
10	Modified,
11	/// Entry was renamed between old and new
12	Renamed,
13	/// Entry was copied from another old entry
14	Copied,
15	/// Type of entry changed between old and new
16	Typechange,
17	/// Other type of change not normally found in a rebase
18	Other,
19}
20
21impl Status {
22	/// Create a new status for a `git2::Delta`.
23	#[must_use]
24	#[inline]
25	pub const fn from(delta: git2::Delta) -> Self {
26		match delta {
27			git2::Delta::Added => Self::Added,
28			git2::Delta::Copied => Self::Copied,
29			git2::Delta::Deleted => Self::Deleted,
30			git2::Delta::Modified => Self::Modified,
31			git2::Delta::Renamed => Self::Renamed,
32			git2::Delta::Typechange => Self::Typechange,
33			git2::Delta::Ignored
34			| git2::Delta::Conflicted
35			| git2::Delta::Unmodified
36			| git2::Delta::Unreadable
37			| git2::Delta::Untracked => Self::Other,
38		}
39	}
40}
41
42#[cfg(test)]
43mod tests {
44	use git2::Delta;
45	use rstest::rstest;
46
47	use super::*;
48
49	#[rstest]
50	#[case::added(Delta::Added, Status::Added)]
51	#[case::copied(Delta::Copied, Status::Copied)]
52	#[case::deleted(Delta::Deleted, Status::Deleted)]
53	#[case::modified(Delta::Modified, Status::Modified)]
54	#[case::renamed(Delta::Renamed, Status::Renamed)]
55	#[case::typechange(Delta::Typechange, Status::Typechange)]
56	#[case::ignored(Delta::Ignored, Status::Other)]
57	#[case::conflicted(Delta::Conflicted, Status::Other)]
58	#[case::unmodified(Delta::Unmodified, Status::Other)]
59	#[case::unreadable(Delta::Unreadable, Status::Other)]
60	#[case::untracked(Delta::Untracked, Status::Other)]
61	fn from_delta(#[case] input: Delta, #[case] expected: Status) {
62		assert_eq!(Status::from(input), expected);
63	}
64}