mod support;
use anyhow::Result;
use git2::Repository;
use thoughts_tool::git::shell_fetch;
use thoughts_tool::git::shell_push;
#[ignore = "integration test - run with: just test-integration"]
#[test]
fn shell_fetch_fetches_from_local_bare_remote() -> Result<()> {
if which::which("git").is_err() {
eprintln!("Skipping integration test: git not found in PATH");
return Ok(());
}
let tmp = tempfile::TempDir::new()?;
let base = tmp.path();
let bare_path = base.join("remote_bare.git");
let upstream_path = base.join("upstream");
let local_path = base.join("local");
Repository::init_bare(&bare_path)?;
{
let upstream = Repository::init(&upstream_path)?;
std::fs::write(upstream_path.join("README.md"), "hello")?;
let mut idx = upstream.index()?;
idx.add_path(std::path::Path::new("README.md"))?;
idx.write()?;
let tree_id = idx.write_tree()?;
let tree = upstream.find_tree(tree_id)?;
let sig = git2::Signature::now("Test", "test@example.com")?;
upstream.commit(Some("HEAD"), &sig, &sig, "init", &tree, &[])?;
support::git_ok(&upstream_path, &["branch", "-M", "main"]);
upstream.remote("origin", bare_path.to_str().unwrap())?;
shell_push::push_current_branch(&upstream_path, "origin", "main")?;
}
let local = Repository::init(&local_path)?;
local.remote("origin", bare_path.to_str().unwrap())?;
shell_fetch::fetch(&local_path, "origin")?;
let local = Repository::open(&local_path)?;
let remote_ref = local.find_reference("refs/remotes/origin/main")?;
let _oid = remote_ref
.target()
.expect("origin/main should have a target");
Ok(())
}