Skip to content

Commit c45f2a6

Browse files
committed
wip!: orphan branch with initial commit for variant
the initial commit will house metadata on the variant that is being derived like the author, the configs and so on.
1 parent 060e359 commit c45f2a6

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::{Context, Result};
2-
use git2::{BranchType, Commit, Repository, Sort};
2+
use git2::{BranchType, Commit, Repository, Signature, Sort};
33
use regex::Regex;
44
use std::fs;
55
use std::io::Write;
@@ -42,6 +42,28 @@ pub fn init(repo: &Repository) -> Result<()> {
4242
pub fn derive(repo: &Repository, name: &str, features: &[String]) -> Result<()> {
4343
println!("Deriving variant '{}' with features: {:?}", name, features);
4444
// create a new orphan branch
45+
let tree_oid = repo
46+
.treebuilder(None)?
47+
.write()
48+
.context("Failed to create empty tree.")?;
49+
let tree = repo.find_tree(tree_oid)?;
50+
println!("Treeid: {:?}", tree_oid);
51+
52+
let sig = Signature::now("user", "user@example.com")?;
53+
54+
let ref_name = format!("refs/heads/variant/{name}");
55+
let commit_oid = repo
56+
.commit(
57+
Some(&ref_name),
58+
&sig,
59+
&sig,
60+
"Variant initial commit\n",
61+
&tree,
62+
&[],
63+
)
64+
.context("Failed to create initial commit for variant")?;
65+
println!("Commit id: {:?}", commit_oid);
66+
4567
// walk the commit graph
4668
let mut revwalk = repo.revwalk()?;
4769
revwalk.push_head()?;

0 commit comments

Comments
 (0)