summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Dahlberg <git@valleymnt.com>2022-11-09 22:30:16 +0100
committerNick Gerace <nickagerace@gmail.com>2022-12-19 18:10:16 -0500
commitfa71d230e8f6efe28a1c9c11874432ca575e3440 (patch)
treee9e23ba8043c666c84368d661de61e68169f7864
parent82a8a4bd78ab17a2b509ae7272d045fa86d51f1c (diff)
downloadgfold-fa71d230e8f6efe28a1c9c11874432ca575e3440.zip
test: add failing test for #202
-rw-r--r--crates/gfold/src/main.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/gfold/src/main.rs b/crates/gfold/src/main.rs
index b0d069a..eec0790 100644
--- a/crates/gfold/src/main.rs
+++ b/crates/gfold/src/main.rs
@@ -39,6 +39,8 @@ mod tests {
use anyhow::{anyhow, Result};
use git2::ErrorCode;
use git2::Repository;
+ use git2::Signature;
+ use git2::Oid;
use pretty_assertions::assert_eq;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
@@ -98,6 +100,8 @@ mod tests {
return Err(e.into());
}
}
+
+ create_branch(&repository, "feat")?;
}
}
@@ -225,4 +229,42 @@ mod tests {
}
Ok(())
}
+
+ fn create_branch(repository: &Repository, name: &str) -> Result<()> {
+ // we need to commit something before branching
+ let commit_oid = commit(repository)?;
+ repository.branch(name, &repository.find_commit(commit_oid).unwrap(), true).unwrap();
+
+ Ok(())
+ }
+
+ // taken from https://github.com/rust-lang/git2-rs/pull/885
+ fn commit(repository: &Repository) -> Result<Oid> {
+ // We will commit the content of the index
+ let mut index = repository.index()?;
+ let tree_oid = index.write_tree()?;
+ let tree = repository.find_tree(tree_oid)?;
+
+ let parent_commit = match repository.revparse_single("HEAD") {
+ Ok(obj) => Some(obj.into_commit().unwrap()),
+ // First commit so no parent commit
+ Err(e) if e.code() == ErrorCode::NotFound => None,
+ Err(_e) => panic!(),
+ };
+
+ let mut parents = Vec::new();
+ if parent_commit.is_some() {
+ parents.push(parent_commit.as_ref().unwrap());
+ }
+
+ let sig = Signature::now("Bob", "bob@bob").unwrap();
+ Ok(repository.commit(
+ Some("HEAD"),
+ &sig,
+ &sig,
+ "hello",
+ &tree,
+ &parents[..],
+ )?)
+ }
}