guanghu/src-tauri/tests/git_connect_no_remote.rs
Guanghu Domestic Migration 9b41d51231
Some checks are pending
Auto-update PR branches / Update open PR branches (push) Waiting to run
CI / Frontend Static Quality Checks (push) Waiting to run
CI / Frontend Tests & Coverage (push) Waiting to run
CI / Rust Tests & Quality Checks (push) Waiting to run
CI / Linux build verification (push) Waiting to run
Deploy docs / Build VitePress site (push) Waiting to run
Deploy docs / Deploy to GitHub Pages (push) Blocked by required conditions
Release (Alpha) / Compute alpha version (push) Waiting to run
Release (Alpha) / Build release artifacts (push) Blocked by required conditions
Release (Alpha) / GitHub Release (alpha) (push) Blocked by required conditions
Release (Alpha) / Update docs and release pages (push) Blocked by required conditions
chore: import sanitized domestic snapshot for REPO-004
Source snapshot: 514ab1975951d94342ea38e64101d5a0f1c51c77
2026-07-17 15:55:28 +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
);
}