gitbutler/gitbutler-app/tests/suite/gb_repository.rs

150 lines
5.0 KiB
Rust
Raw Normal View History

use crate::common::{paths, TestProject};
use gitbutler_app::{gb_repository, git, project_repository, projects};
2023-12-05 17:58:43 +03:00
use std::path;
mod init {
use super::*;
#[test]
fn handle_file_symlink() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
let project = projects
.add(test_project.path())
.expect("failed to add project");
std::fs::write(project.path.join("file"), "content").unwrap();
std::fs::hard_link(project.path.join("file"), project.path.join("link")).unwrap();
2023-11-14 17:19:22 +03:00
let project_repository = project_repository::Repository::open(&project).unwrap();
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
}
#[test]
2024-03-04 18:56:30 +03:00
#[cfg(target_family = "unix")]
fn handle_dir_symlink() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
let project = projects
.add(test_project.path())
.expect("failed to add project");
2023-11-02 11:21:05 +03:00
std::fs::create_dir_all(project.path.join("dir")).unwrap();
std::fs::write(project.path.join("dir/file"), "content").unwrap();
std::os::unix::fs::symlink(project.path.join("dir"), project.path.join("dir_link"))
.unwrap();
2023-11-14 17:19:22 +03:00
let project_repository = project_repository::Repository::open(&project).unwrap();
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
}
2023-11-02 11:00:07 +03:00
#[test]
2024-03-04 18:56:30 +03:00
#[cfg(target_family = "unix")]
2023-11-02 11:00:07 +03:00
fn handle_dir_symlink_symlink() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
2023-11-02 11:00:07 +03:00
let project = projects
.add(test_project.path())
.expect("failed to add project");
2023-11-02 11:21:05 +03:00
std::fs::create_dir_all(project.path.join("dir")).unwrap();
2023-11-02 11:00:07 +03:00
std::fs::write(project.path.join("dir/file"), "content").unwrap();
std::os::unix::fs::symlink(project.path.join("dir"), project.path.join("dir_link"))
.unwrap();
std::os::unix::fs::symlink(
project.path.join("dir_link"),
project.path.join("link_link"),
)
.unwrap();
2023-11-14 17:19:22 +03:00
let project_repository = project_repository::Repository::open(&project).unwrap();
2023-11-02 11:00:07 +03:00
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
2023-11-02 11:00:07 +03:00
}
}
mod flush {
use super::*;
#[test]
fn handle_file_symlink() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
let project = projects
.add(test_project.path())
.expect("failed to add project");
2023-11-14 17:19:22 +03:00
let project_repository = project_repository::Repository::open(&project).unwrap();
let gb_repo =
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
std::fs::write(project.path.join("file"), "content").unwrap();
std::fs::hard_link(project.path.join("file"), project.path.join("link")).unwrap();
gb_repo.flush(&project_repository, None).unwrap();
}
#[test]
2024-03-04 18:56:30 +03:00
#[cfg(target_family = "unix")]
fn handle_dir_symlink() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
let project = projects
.add(test_project.path())
.expect("failed to add project");
2023-11-14 17:19:22 +03:00
let project_repository = project_repository::Repository::open(&project).unwrap();
let gb_repo =
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
2023-11-02 11:21:05 +03:00
std::fs::create_dir_all(project.path.join("dir")).unwrap();
std::fs::write(project.path.join("dir/file"), "content").unwrap();
std::os::unix::fs::symlink(project.path.join("dir"), project.path.join("dir_link"))
.unwrap();
gb_repo.flush(&project_repository, None).unwrap();
}
2023-11-17 16:05:00 +03:00
#[test]
fn handle_submodules() {
let test_project = TestProject::default();
let data_dir = paths::data_dir();
let projects = projects::Controller::from_path(&data_dir);
2023-11-17 16:05:00 +03:00
let project = projects
.add(test_project.path())
.expect("failed to add project");
let project_repository = project_repository::Repository::open(&project).unwrap();
let gb_repo =
gb_repository::Repository::open(data_dir.path(), &project_repository, None).unwrap();
2023-11-17 16:05:00 +03:00
let project = TestProject::default();
let submodule_url: git::Url = project.path().display().to_string().parse().unwrap();
2023-11-17 16:05:00 +03:00
test_project.add_submodule(&submodule_url, path::Path::new("submodule"));
gb_repo.flush(&project_repository, None).unwrap();
}
}