Replace the three error styles with one Error type and one Result alias in error.rs. The error crosses IPC as the same plain string as before. The message text does not change. Move the shared file mechanics to fsutil.rs. These are the reserved-name check, the link and junction check, the limited reads, and the atomic writes. Each module keeps its own path rules, limits, and messages. The plugin settings writer now flushes its file to disk before the rename. Remove the current_root_path and list_entries wrappers and an unused mime value. Use named windows-sys constants for the process, file, drive, and error codes. Add a test that compares the command lists in lib.rs, build.rs, and the capability files. The settings capability must be a subset of the full list. In Cargo.toml, set the author, keep only the rlib crate type, and remove the unused thiserror dependency. Remove panic = "abort" from the release profile. A panic on a worker thread then stops only that thread. It does not stop the editor with unsaved buffers.
184 lines
6.8 KiB
Rust
184 lines
6.8 KiB
Rust
use super::*;
|
|
|
|
struct Fixture(PathBuf);
|
|
impl Fixture {
|
|
fn new() -> Self {
|
|
let root =
|
|
std::env::temp_dir().join(format!("runestone-git-sync-{}", uuid::Uuid::new_v4()));
|
|
std::fs::create_dir_all(&root).unwrap();
|
|
let fixture = Self(dunce::canonicalize(root).unwrap());
|
|
fixture.git(
|
|
".",
|
|
&["init", "--bare", "--initial-branch=main", "remote.git"],
|
|
);
|
|
fixture.git(".", &["clone", "remote.git", "local"]);
|
|
for directory in ["local"] {
|
|
fixture.git(directory, &["config", "user.name", "RuneStone Test"]);
|
|
fixture.git(directory, &["config", "user.email", "[email protected]"]);
|
|
}
|
|
fixture
|
|
}
|
|
fn path(&self, directory: &str) -> PathBuf {
|
|
self.0.join(directory)
|
|
}
|
|
fn git(&self, directory: &str, args: &[&str]) -> String {
|
|
checked(&self.path(directory), args).unwrap()
|
|
}
|
|
fn commit(&self, directory: &str, name: &str, contents: &str) {
|
|
std::fs::write(self.path(directory).join(name), contents).unwrap();
|
|
self.git(directory, &["add", "--", name]);
|
|
self.git(
|
|
directory,
|
|
&[
|
|
"-c",
|
|
"user.name=RuneStone Test",
|
|
"-c",
|
|
"[email protected]",
|
|
"commit",
|
|
"-m",
|
|
contents,
|
|
],
|
|
);
|
|
}
|
|
fn seed(&self) {
|
|
self.commit("local", "first.txt", "Initial commit");
|
|
synchronize(&self.path("local"), true).unwrap();
|
|
self.git(".", &["clone", "remote.git", "peer"]);
|
|
}
|
|
}
|
|
impl Drop for Fixture {
|
|
fn drop(&mut self) {
|
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn push_and_fast_forward_pull_use_only_the_upstream_branch() {
|
|
let fixture = Fixture::new();
|
|
fixture.seed();
|
|
fixture.git("local", &["branch", "unpublished"]);
|
|
fixture.git("local", &["tag", "unpublished-tag"]);
|
|
fixture.git("local", &["config", "push.default", "matching"]);
|
|
fixture.git("local", &["config", "remote.origin.mirror", "true"]);
|
|
fixture.commit("local", "second.txt", "Local change");
|
|
synchronize(&fixture.path("local"), true).unwrap();
|
|
let refs = fixture.git("remote.git", &["for-each-ref", "--format=%(refname)"]);
|
|
assert_eq!(refs.trim(), "refs/heads/main");
|
|
fixture.git("peer", &["pull", "--ff-only"]);
|
|
fixture.commit("peer", "peer.txt", "Peer change");
|
|
fixture.git("peer", &["push"]);
|
|
fixture.git("local", &["config", "pull.rebase", "true"]);
|
|
synchronize(&fixture.path("local"), false).unwrap();
|
|
assert_eq!(
|
|
fixture.git("local", &["rev-parse", "HEAD"]),
|
|
fixture.git("peer", &["rev-parse", "HEAD"])
|
|
);
|
|
assert_eq!(
|
|
std::fs::read_to_string(fixture.path("local").join("peer.txt")).unwrap(),
|
|
"Peer change"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn divergent_push_and_pull_preserve_local_and_remote_commits() {
|
|
let fixture = Fixture::new();
|
|
fixture.seed();
|
|
fixture.commit("peer", "peer.txt", "Peer change");
|
|
fixture.git("peer", &["push"]);
|
|
fixture.commit("local", "local.txt", "Local change");
|
|
fixture.git(
|
|
"local",
|
|
&[
|
|
"config",
|
|
"remote.origin.push",
|
|
"+refs/heads/main:refs/heads/main",
|
|
],
|
|
);
|
|
fixture.git("local", &["config", "pull.rebase", "true"]);
|
|
fixture.git("local", &["config", "pull.ff", "false"]);
|
|
let local = fixture.git("local", &["rev-parse", "HEAD"]);
|
|
let remote = fixture.git("remote.git", &["rev-parse", "HEAD"]);
|
|
assert!(synchronize(&fixture.path("local"), true).is_err());
|
|
assert!(synchronize(&fixture.path("local"), false).is_err());
|
|
assert_eq!(fixture.git("local", &["rev-parse", "HEAD"]), local);
|
|
assert_eq!(fixture.git("remote.git", &["rev-parse", "HEAD"]), remote);
|
|
assert!(!fixture.path("local/.git/MERGE_HEAD").exists());
|
|
assert!(!fixture.path("local/.git/rebase-merge").exists());
|
|
}
|
|
|
|
#[test]
|
|
fn dirty_missing_upstream_detached_and_remote_errors_are_clear() {
|
|
let fixture = Fixture::new();
|
|
fixture.seed();
|
|
std::fs::write(fixture.path("local/first.txt"), "Unsaved change").unwrap();
|
|
fixture.git("local", &["config", "merge.autoStash", "true"]);
|
|
assert!(synchronize(&fixture.path("local"), false)
|
|
.unwrap_err()
|
|
.to_string()
|
|
.contains("clean working tree"));
|
|
assert_eq!(
|
|
std::fs::read_to_string(fixture.path("local/first.txt")).unwrap(),
|
|
"Unsaved change"
|
|
);
|
|
fixture.git("local", &["branch", "--unset-upstream"]);
|
|
assert!(synchronize(&fixture.path("local"), true)
|
|
.unwrap_err()
|
|
.to_string()
|
|
.contains("no remote upstream"));
|
|
fixture.git("local", &["checkout", "--detach"]);
|
|
assert!(synchronize(&fixture.path("local"), true)
|
|
.unwrap_err()
|
|
.to_string()
|
|
.contains("Select a branch"));
|
|
fixture.git("local", &["checkout", "main"]);
|
|
fixture.git("local", &["branch", "--set-upstream-to=origin/main"]);
|
|
fixture.git(
|
|
"local",
|
|
&["remote", "set-url", "origin", "../missing-remote.git"],
|
|
);
|
|
assert!(synchronize(&fixture.path("local"), true)
|
|
.unwrap_err()
|
|
.to_string()
|
|
.contains("Push failed"));
|
|
}
|
|
|
|
#[test]
|
|
fn graph_shows_branch_forks_merges_tags_and_detached_history() {
|
|
let fixture = Fixture::new();
|
|
assert!(graph(&fixture.path("local")).unwrap().commits.is_empty());
|
|
fixture.seed();
|
|
fixture.git("local", &["checkout", "-b", "feature"]);
|
|
fixture.commit("local", "feature.txt", "Feature commit");
|
|
fixture.git("local", &["checkout", "main"]);
|
|
fixture.commit("local", "main.txt", "Main commit");
|
|
fixture.git(
|
|
"local",
|
|
&["merge", "--no-ff", "feature", "-m", "Merge feature"],
|
|
);
|
|
fixture.git("local", &["tag", "test-tag"]);
|
|
let history = graph(&fixture.path("local")).unwrap();
|
|
for expected in [
|
|
"HEAD -> main",
|
|
"feature",
|
|
"test-tag",
|
|
"Merge feature",
|
|
"RuneStone Test",
|
|
] {
|
|
assert!(format!("{history:?}").contains(expected), "Missing {expected}: {history:?}");
|
|
}
|
|
let merge = history.commits.iter().find(|commit| commit.summary == "Merge feature").unwrap();
|
|
assert_eq!(merge.parents.len(), 2);
|
|
let details = commit_details(&fixture.path("local"), &merge.id).unwrap();
|
|
assert_eq!(details.files.len(), 1);
|
|
assert_eq!(details.files[0].path, "feature.txt");
|
|
assert!(commit_diff(&fixture.path("local"), &merge.id, "feature.txt").unwrap().contains("+Feature commit"));
|
|
for parent in &merge.parents {
|
|
assert!(history.commits.iter().any(|commit| &commit.id == parent));
|
|
}
|
|
fixture.git("local", &["checkout", "--detach"]);
|
|
fixture.commit("local", "detached.txt", "Detached commit");
|
|
assert!(graph(&fixture.path("local"))
|
|
.unwrap()
|
|
.commits.iter().any(|commit| commit.summary == "Detached commit"));
|
|
}
|