mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-27 03:22:15 +03:00
72291ce4cb
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
100 lines
2.5 KiB
Rust
100 lines
2.5 KiB
Rust
use std::fs;
|
|
|
|
use anyhow::Result;
|
|
use gitbutler_app::watcher::{handlers, handlers::git_file_change::Handler, Event};
|
|
use gitbutler_core::projects;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use crate::shared::{Case, Suite};
|
|
|
|
#[test]
|
|
fn flush_session() -> Result<()> {
|
|
let suite = Suite::default();
|
|
let Case {
|
|
project,
|
|
gb_repository,
|
|
..
|
|
} = &suite.new_case();
|
|
|
|
assert!(gb_repository.get_current_session()?.is_none());
|
|
create_new_session_via_new_file(project, &suite);
|
|
assert!(gb_repository.get_current_session()?.is_some());
|
|
|
|
let listener = Handler::new(
|
|
suite.local_app_data().into(),
|
|
suite.projects.clone(),
|
|
suite.users.clone(),
|
|
);
|
|
|
|
let flush_file_path = project.path.join(".git/GB_FLUSH");
|
|
fs::write(flush_file_path.as_path(), "")?;
|
|
|
|
let result = listener.handle("GB_FLUSH", &project.id)?;
|
|
|
|
assert_eq!(result.len(), 1);
|
|
assert!(matches!(result[0], Event::Flush(_, _)));
|
|
|
|
assert!(!flush_file_path.exists(), "flush file deleted");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn do_not_flush_session_if_file_is_missing() -> Result<()> {
|
|
let suite = Suite::default();
|
|
let Case {
|
|
project,
|
|
gb_repository,
|
|
..
|
|
} = &suite.new_case();
|
|
|
|
assert!(gb_repository.get_current_session()?.is_none());
|
|
create_new_session_via_new_file(project, &suite);
|
|
assert!(gb_repository.get_current_session()?.is_some());
|
|
|
|
let listener = Handler::new(
|
|
suite.local_app_data().into(),
|
|
suite.projects.clone(),
|
|
suite.users.clone(),
|
|
);
|
|
|
|
let result = listener.handle("GB_FLUSH", &project.id)?;
|
|
|
|
assert_eq!(result.len(), 0);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn create_new_session_via_new_file(project: &projects::Project, suite: &Suite) {
|
|
fs::write(project.path.join("test.txt"), "test").unwrap();
|
|
|
|
let file_change_listener =
|
|
handlers::calculate_deltas_handler::Handler::from_path(suite.local_app_data());
|
|
file_change_listener
|
|
.handle("test.txt", &project.id)
|
|
.unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn flush_deletes_flush_file_without_session_to_flush() -> Result<()> {
|
|
let suite = Suite::default();
|
|
let Case { project, .. } = &suite.new_case();
|
|
|
|
let listener = Handler::new(
|
|
suite.local_app_data().into(),
|
|
suite.projects.clone(),
|
|
suite.users.clone(),
|
|
);
|
|
|
|
let flush_file_path = project.path.join(".git/GB_FLUSH");
|
|
fs::write(flush_file_path.as_path(), "")?;
|
|
|
|
let result = listener.handle("GB_FLUSH", &project.id)?;
|
|
|
|
assert_eq!(result.len(), 0);
|
|
|
|
assert!(!flush_file_path.exists(), "flush file deleted");
|
|
|
|
Ok(())
|
|
}
|