gitbutler/crates/gitbutler-core/tests/shared/mod.rs
Sebastian Thiel 72291ce4cb
chore: align 'app' and 'lib' crates imports.
This is done one-time (for now) using a nightly feature of cargo-fmt
as defined in `rustfmt-nightly.toml.`

It's planned to make this the default so imports will always be sorted.
For now it can be run manually with:
    cargo +nightly fmt -- --config-path rustfmt-nightly.toml
or
    pnpm rustfmtTBD
 Please enter the message for your patch. Lines starting with
2024-03-30 22:43:16 +01:00

64 lines
1.8 KiB
Rust

pub const VAR_NO_CLEANUP: &str = "GITBUTLER_TESTS_NO_CLEANUP";
mod test_project;
pub use test_project::TestProject;
mod suite;
pub use suite::*;
pub mod paths {
use tempfile::TempDir;
use super::temp_dir;
pub fn data_dir() -> TempDir {
temp_dir()
}
}
pub mod virtual_branches {
use gitbutler_core::{gb_repository, project_repository, virtual_branches};
use crate::shared::empty_bare_repository;
pub fn set_test_target(
gb_repo: &gb_repository::Repository,
project_repository: &project_repository::Repository,
) -> anyhow::Result<()> {
let (remote_repo, _tmp) = empty_bare_repository();
let mut remote = project_repository
.git_repository
.remote(
"origin",
&remote_repo.path().to_str().unwrap().parse().unwrap(),
)
.expect("failed to add remote");
remote.push(&["refs/heads/master:refs/heads/master"], None)?;
virtual_branches::target::Writer::new(gb_repo, project_repository.project().gb_dir())?
.write_default(&virtual_branches::target::Target {
branch: "refs/remotes/origin/master".parse().unwrap(),
remote_url: remote_repo.path().to_str().unwrap().parse().unwrap(),
sha: remote_repo.head().unwrap().target().unwrap(),
})
.expect("failed to write target");
virtual_branches::integration::update_gitbutler_integration(gb_repo, project_repository)
.expect("failed to update integration");
Ok(())
}
}
pub fn init_opts() -> git2::RepositoryInitOptions {
let mut opts = git2::RepositoryInitOptions::new();
opts.initial_head("master");
opts
}
pub fn init_opts_bare() -> git2::RepositoryInitOptions {
let mut opts = init_opts();
opts.bare(true);
opts
}