Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit c4ed9f8

Browse files
committed
feat: add initial trait method and accompanying implementation
1 parent 275207f commit c4ed9f8

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

src/lib.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
1-
pub fn add(left: u64, right: u64) -> u64 {
2-
left + right
1+
///! Testingg
2+
use git2;
3+
use git2::{Error, Repository};
4+
5+
#[derive(Debug)]
6+
pub struct MetadataOptions {
7+
pub name: String,
8+
pub shard_level: u8,
9+
pub force: bool,
10+
}
11+
12+
impl Default for MetadataOptions {
13+
fn default() -> Self {
14+
Self {
15+
name: "refs/metadata/commits".to_string(),
16+
shard_level: 4,
17+
force: false,
18+
}
19+
}
320
}
421

5-
#[cfg(test)]
6-
mod tests {
7-
use super::*;
22+
pub trait MetadataIndex<'a> {
23+
fn add_metadata(
24+
&'a self,
25+
oid: &git2::Oid,
26+
metadata: &git2::Tree,
27+
maybe_commit: Option<&git2::Commit>,
28+
maybe_opts: Option<&MetadataOptions>,
29+
) -> Result<git2::Reference<'a>, Error>;
30+
}
31+
32+
impl<'a> MetadataIndex<'a> for Repository {
33+
fn add_metadata(
34+
&'a self,
35+
oid: &git2::Oid,
36+
metadata: &git2::Tree,
37+
maybe_commit: Option<&git2::Commit>,
38+
maybe_opts: Option<&MetadataOptions>,
39+
) -> Result<git2::Reference<'a>, Error> {
40+
let commit = maybe_commit.unwrap_or(&self.head()?.peel_to_commit()?);
41+
42+
let default_opts = MetadataOptions::default();
43+
let opts = maybe_opts.unwrap_or(&default_opts);
44+
45+
let reference = match self.find_reference(&opts.name) {
46+
Ok(reference) => Some(reference),
47+
Err(e) if e.code() == git2::ErrorCode::NotFound => None,
48+
Err(e) => return Err(e),
49+
};
850

9-
#[test]
10-
fn it_works() {
11-
let result = add(2, 2);
12-
assert_eq!(result, 4);
51+
todo!()
1352
}
1453
}

0 commit comments

Comments
 (0)