guanghu/src-tauri/tests/git_connect_no_remote.rs
冰朔 8739805f99
Some checks failed
Auto-update PR branches / Update open PR branches (push) Has been cancelled
CI / Frontend Static Quality Checks (push) Has been cancelled
CI / Frontend Tests & Coverage (push) Has been cancelled
CI / Rust Tests & Quality Checks (push) Has been cancelled
CI / Linux build verification (push) Has been cancelled
Release (Alpha) / Compute alpha version (push) Has been cancelled
Release (Alpha) / Build release artifacts (push) Has been cancelled
Release (Alpha) / GitHub Release (alpha) (push) Has been cancelled
Release (Alpha) / Update docs and release pages (push) Has been cancelled
Deploy docs / Build VitePress site (push) Has been cancelled
Deploy docs / Deploy to GitHub Pages (push) Has been cancelled
光湖开源源码快照 · Tolaria AGPL 分叉基线 · 独立更新链
2026-07-05 17:45:16 +08:00

62 lines
1.5 KiB
Rust

use std::fs;
use std::path::Path;
use std::process::Command;
use tempfile::TempDir;
use tolaria_lib::git::{git_add_remote, git_commit, git_remote_status};
fn run_git(path: &Path, args: &[&str]) {
let output = Command::new("git")
.args(args)
.current_dir(path)
.output()
.unwrap();
assert!(
output.status.success(),
"git {:?} failed: {}",
args,
String::from_utf8_lossy(&output.stderr)
);
}
fn setup_repo() -> TempDir {
let dir = TempDir::new().unwrap();
run_git(dir.path(), &["init", "-b", "main"]);
dir
}
fn setup_bare_repo() -> TempDir {
let dir = TempDir::new().unwrap();
run_git(dir.path(), &["init", "--bare"]);
dir
}
#[test]
fn git_add_remote_ignores_name_only_origin_config() {
let local = setup_repo();
fs::write(local.path().join("note.md"), "# Note\n").unwrap();
git_commit(local.path().to_str().unwrap(), "initial").unwrap();
run_git(local.path(), &["config", "remote.origin.prune", "true"]);
let remote_names = Command::new("git")
.args(["remote"])
.current_dir(local.path())
.output()
.unwrap();
assert!(String::from_utf8_lossy(&remote_names.stdout).contains("origin"));
let bare = setup_bare_repo();
let result = git_add_remote(
local.path().to_str().unwrap(),
bare.path().to_str().unwrap(),
)
.unwrap();
assert_eq!(result.status, "connected");
assert!(
git_remote_status(local.path().to_str().unwrap())
.unwrap()
.has_remote
);
}