How to use git2::Remote::push correctly?

since you didn't show your implementation, I can't be sure which API you might be missing, so I recreated these commands using libgit2, you can compare my API calls to your implementation to figure out the missing part.

use std::{fs, path};

use git2::build::RepoBuilder;
use git2::{IndexAddOption, Repository, Signature};

fn main() {
	let root_dir = path::Path::new("Z:/Temp");
	let base_path = root_dir.join("base");
	let remote_path = root_dir.join("remote");
	let clone_path = root_dir.join("clone");
	let author = Signature::now("user", "").unwrap();

	// create base repo and remote bare repo
	let base_repo = Repository::init(&base_path).unwrap();
	let remote_repo = Repository::init_bare(&remote_path).unwrap();
	let remote_url = format!("file:///{}", remote_repo.path().display());

	// create a text file and add it to index
	fs::write(base_path.join("hello.txt"), "hello world!\n").unwrap();
	let mut base_index = base_repo.index().unwrap();
		.add_all(["."], IndexAddOption::DEFAULT, None)

	// make the commit, since it's the initial commit, there's no parent
	let tree = base_repo
	let commit_oid = base_repo
		.commit(None, &author, &author, "initial", &tree, &[])

	// update branch pointer
	let branch = base_repo
		.branch("main", &base_repo.find_commit(commit_oid).unwrap(), true)

	// add remote as "origin" and push the branch
	let mut origin = base_repo.remote("origin", &remote_url).unwrap();
		.push(&[branch.into_reference().name().unwrap()], None)

	// clone from remote
	let clone_repo = RepoBuilder::new()
		.clone(&remote_url, &clone_path)

	// examine the commit message:
		"short commit message: {}",
1 Like