replace calls to git2
with calls to git
cli
This commit is contained in:
parent
5da7e69f82
commit
d321788d7c
66
Cargo.lock
generated
66
Cargo.lock
generated
|
@ -74,7 +74,6 @@ version = "1.0.83"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
]
|
||||
|
||||
|
@ -171,7 +170,6 @@ name = "forgejo-api"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"eyre",
|
||||
"git2",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -236,21 +234,6 @@ version = "0.28.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
|
||||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd"
|
||||
dependencies = [
|
||||
"bitflags 2.4.1",
|
||||
"libc",
|
||||
"libgit2-sys",
|
||||
"log",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.21"
|
||||
|
@ -385,15 +368,6 @@ version = "1.0.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.65"
|
||||
|
@ -415,46 +389,6 @@ version = "0.2.150"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
version = "0.16.1+1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2a2bb3680b094add03bb3732ec520ece34da31a8cd2d633d1389d0f0fb60d0c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"libssh2-sys",
|
||||
"libz-sys",
|
||||
"openssl-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libssh2-sys"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"libz-sys",
|
||||
"openssl-sys",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.11"
|
||||
|
|
|
@ -18,4 +18,3 @@ serde_json = "1.0.108"
|
|||
[dev-dependencies]
|
||||
eyre = "0.6.9"
|
||||
tokio = { version = "1.29.1", features = ["net", "fs", "rt", "macros"] }
|
||||
git2 = "0.18.1"
|
||||
|
|
|
@ -52,20 +52,18 @@ async fn user(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
|
|||
|
||||
async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
|
||||
tokio::fs::create_dir("/test_repo").await?;
|
||||
let local_repo = git2::Repository::init("/test_repo")?;
|
||||
let git = || {
|
||||
let mut cmd = std::process::Command::new("git");
|
||||
cmd.current_dir("/test_repo");
|
||||
cmd
|
||||
};
|
||||
let _ = git().args(["config", "user.name", "TestingAdmin"]).status()?;
|
||||
let _ = git().args(["config", "user.email", "admin@noreply.example.org"]).status()?;
|
||||
let _ = git().args(["init"]).status()?;
|
||||
tokio::fs::write("/test_repo/README.md", "# Test\nThis is a test repo").await?;
|
||||
let _ = git().args(["add", "."]).status()?;
|
||||
let _ = git().args(["commit", "-m", "initial commit"]).status()?;
|
||||
|
||||
let mut index = local_repo.index()?;
|
||||
index.add_all(["."], git2::IndexAddOption::DEFAULT, None)?;
|
||||
index.write()?;
|
||||
let tree = local_repo.find_tree(index.write_tree().unwrap())?;
|
||||
let author = git2::Signature::now("TestingAdmin", "admin@noreply.example.org").unwrap();
|
||||
let commit_oid = local_repo.commit(None, &author, &author, "bibblybeebly", &tree, &[])?;
|
||||
let root_commit = local_repo.find_commit(commit_oid).unwrap();
|
||||
let branch = local_repo.branch("main", &root_commit, true)?;
|
||||
let branch_ref = branch.into_reference();
|
||||
let branch_ref_name = branch_ref.name().ok_or_else(|| eyre!("branch name not found"))?;
|
||||
local_repo.set_head(branch_ref_name)?;
|
||||
|
||||
let repo_opt = forgejo_api::CreateRepoOption {
|
||||
auto_init: false,
|
||||
|
@ -85,33 +83,17 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
|
|||
ensure!(remote_repo.owner.login == "TestingAdmin", "repo owner is not \"TestingAdmin\"");
|
||||
ensure!(remote_repo.name == "test", "repo owner is not \"test\"");
|
||||
|
||||
let mut callbacks = git2::RemoteCallbacks::new();
|
||||
callbacks.credentials(|_url, _username_from_url, _allowed_types| {
|
||||
git2::Cred::userpass_plaintext("TestingAdmin", "password")
|
||||
});
|
||||
let mut push_options = git2::PushOptions::new();
|
||||
push_options.remote_callbacks(callbacks);
|
||||
let mut origin = local_repo.remote("origin", remote_repo.clone_url.as_str())?;
|
||||
origin.push(&[dbg!(branch_ref_name)], Some(&mut push_options))?;
|
||||
let mut remote_url = remote_repo.clone_url.clone();
|
||||
remote_url.set_username("TestingAdmin").unwrap();
|
||||
remote_url.set_password(Some("password")).unwrap();
|
||||
let _ = git().args(["remote", "add", "origin", remote_url.as_str()]).status()?;
|
||||
let _ = git().args(["push", "-u", "origin", "main"]).status()?;
|
||||
|
||||
let _ = git().args(["switch", "-c", "test"]).status()?;
|
||||
tokio::fs::write("/test_repo/example.rs", "fn add_one(x: u32) -> u32 { x + 1 }").await?;
|
||||
let mut index = local_repo.index()?;
|
||||
index.add_all(["."], git2::IndexAddOption::DEFAULT, None)?;
|
||||
index.write()?;
|
||||
let tree = local_repo.find_tree(index.write_tree().unwrap())?;
|
||||
let commit_oid = local_repo.commit(None, &author, &author, "egg", &tree, &[&root_commit])?;
|
||||
let branch = local_repo.branch("test", &local_repo.find_commit(commit_oid).unwrap(), true)?;
|
||||
let branch_ref = branch.into_reference();
|
||||
let branch_ref_name = branch_ref.name().ok_or_else(|| eyre!("branch name not found"))?;
|
||||
local_repo.set_head(branch_ref_name)?;
|
||||
|
||||
let mut callbacks = git2::RemoteCallbacks::new();
|
||||
callbacks.credentials(|_url, _username_from_url, _allowed_types| {
|
||||
git2::Cred::userpass_plaintext("TestingAdmin", "password")
|
||||
});
|
||||
let mut push_options = git2::PushOptions::new();
|
||||
push_options.remote_callbacks(callbacks);
|
||||
origin.push(&[dbg!(branch_ref_name)], Some(&mut push_options)).wrap_err("failed to push branch")?;
|
||||
let _ = git().args(["add", "."]).status()?;
|
||||
let _ = git().args(["commit", "-m", "egg"]).status()?;
|
||||
let _ = git().args(["push", "-u", "origin", "test"]).status()?;
|
||||
|
||||
let pr_opt = forgejo_api::CreatePullRequestOption {
|
||||
assignee: None,
|
||||
|
|
Loading…
Reference in a new issue