git/testutil/
build_reference.rs

1use crate::{Reference, ReferenceKind};
2
3/// Builder for creating a new reference.
4#[derive(Debug)]
5pub struct ReferenceBuilder {
6	reference: Reference,
7}
8
9impl ReferenceBuilder {
10	/// Create a new instance of the builder with the provided hash. The new instance will default
11	/// to a branch kind and a name of "main".
12	#[inline]
13	#[must_use]
14	pub fn new(hash: &str) -> Self {
15		Self {
16			reference: Reference {
17				hash: String::from(hash),
18				name: String::from("refs/heads/main"),
19				shorthand: String::from("main"),
20				kind: ReferenceKind::Branch,
21			},
22		}
23	}
24
25	/// Set the hash.
26	#[inline]
27	pub fn hash(&mut self, hash: &str) -> &mut Self {
28		self.reference.hash = String::from(hash);
29		self
30	}
31
32	/// Set the name.
33	#[inline]
34	pub fn name(&mut self, name: &str) -> &mut Self {
35		self.reference.name = String::from(name);
36		self
37	}
38
39	/// Set the shortname.
40	#[inline]
41	pub fn shorthand(&mut self, shorthand: &str) -> &mut Self {
42		self.reference.shorthand = String::from(shorthand);
43		self
44	}
45
46	/// Set the kind.
47	#[inline]
48	pub fn kind(&mut self, kind: ReferenceKind) -> &mut Self {
49		self.reference.kind = kind;
50		self
51	}
52
53	/// Build the `Reference`.
54	#[inline]
55	#[must_use]
56	#[allow(clippy::missing_const_for_fn)]
57	pub fn build(self) -> Reference {
58		self.reference
59	}
60}