fix: WSL Buff 路径支持 + 排除 .blueprint/ 触发 Vite 热重载
This commit is contained in:
parent
30d6823a1f
commit
00a6d4e335
@ -171,14 +171,45 @@ fn check_project(app: &AppHandle, project_path: &str) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 辅助:WSL 路径检测与转换 ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// 判断路径是否为 WSL UNC 路径(\\wsl.localhost\... 或 \\wsl$\...)
|
||||||
|
fn is_wsl_path(path: &str) -> bool {
|
||||||
|
path.starts_with("\\\\wsl.localhost\\") || path.starts_with("\\\\wsl$\\")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 将 WSL UNC 路径转为 Linux 绝对路径(去掉 \\wsl.localhost\Distro 前缀)
|
||||||
|
fn unc_to_linux(path: &str) -> Option<String> {
|
||||||
|
let prefix = if path.starts_with("\\\\wsl.localhost\\") {
|
||||||
|
"\\\\wsl.localhost\\"
|
||||||
|
} else if path.starts_with("\\\\wsl$\\") {
|
||||||
|
"\\\\wsl$\\"
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
let rest = &path[prefix.len()..];
|
||||||
|
let slash_idx = rest.find('\\')?;
|
||||||
|
Some("/".to_string() + &rest[slash_idx + 1..].replace('\\', "/"))
|
||||||
|
}
|
||||||
|
|
||||||
// ── 辅助:git 操作 ────────────────────────────────────────────────────────────
|
// ── 辅助:git 操作 ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
fn get_head_commit(root: &Path) -> Result<String, String> {
|
fn get_head_commit(root: &Path) -> Result<String, String> {
|
||||||
let out = std::process::Command::new("git")
|
let path_str = root.to_string_lossy();
|
||||||
.args(["rev-parse", "HEAD"])
|
let out = if is_wsl_path(&path_str) {
|
||||||
.current_dir(root)
|
let linux = unc_to_linux(&path_str)
|
||||||
.output()
|
.ok_or_else(|| "无法转换 WSL 路径".to_string())?;
|
||||||
.map_err(|e| e.to_string())?;
|
std::process::Command::new("wsl")
|
||||||
|
.args(["git", "-C", &linux, "rev-parse", "HEAD"])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
} else {
|
||||||
|
std::process::Command::new("git")
|
||||||
|
.args(["rev-parse", "HEAD"])
|
||||||
|
.current_dir(root)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
};
|
||||||
|
|
||||||
if out.status.success() {
|
if out.status.success() {
|
||||||
Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())
|
Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())
|
||||||
@ -188,19 +219,32 @@ fn get_head_commit(root: &Path) -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_changed_files(root: &Path, last_commit: Option<&str>) -> Result<Vec<String>, String> {
|
fn get_changed_files(root: &Path, last_commit: Option<&str>) -> Result<Vec<String>, String> {
|
||||||
// 有上次 commit:diff two commits;无:取最新一次 commit 的变更文件
|
let path_str = root.to_string_lossy();
|
||||||
let args: Vec<&str> = if let Some(prev) = last_commit {
|
let out = if is_wsl_path(&path_str) {
|
||||||
vec!["diff", "--name-only", prev, "HEAD"]
|
let linux = unc_to_linux(&path_str)
|
||||||
|
.ok_or_else(|| "无法转换 WSL 路径".to_string())?;
|
||||||
|
let cmd = if let Some(prev) = last_commit {
|
||||||
|
format!("git -C {linux} diff --name-only {prev} HEAD")
|
||||||
|
} else {
|
||||||
|
format!("git -C {linux} diff-tree --no-commit-id -r --name-only HEAD")
|
||||||
|
};
|
||||||
|
std::process::Command::new("wsl")
|
||||||
|
.args(["bash", "-c", &cmd])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
} else {
|
} else {
|
||||||
vec!["diff-tree", "--no-commit-id", "-r", "--name-only", "HEAD"]
|
let args: Vec<&str> = if let Some(prev) = last_commit {
|
||||||
|
vec!["diff", "--name-only", prev, "HEAD"]
|
||||||
|
} else {
|
||||||
|
vec!["diff-tree", "--no-commit-id", "-r", "--name-only", "HEAD"]
|
||||||
|
};
|
||||||
|
std::process::Command::new("git")
|
||||||
|
.args(&args)
|
||||||
|
.current_dir(root)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
|
|
||||||
let out = std::process::Command::new("git")
|
|
||||||
.args(&args)
|
|
||||||
.current_dir(root)
|
|
||||||
.output()
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
if out.status.success() {
|
if out.status.success() {
|
||||||
Ok(String::from_utf8_lossy(&out.stdout)
|
Ok(String::from_utf8_lossy(&out.stdout)
|
||||||
.lines()
|
.lines()
|
||||||
|
|||||||
@ -1143,3 +1143,4 @@ export const getBuffStatus = (projectPath: string) =>
|
|||||||
|
|
||||||
export const listBuffedProjects = () =>
|
export const listBuffedProjects = () =>
|
||||||
invoke<BuffStatus[]>("list_buffed_projects");
|
invoke<BuffStatus[]>("list_buffed_projects");
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,8 @@ export default defineConfig(async () => ({
|
|||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
watch: {
|
watch: {
|
||||||
// 3. tell Vite to ignore watching `src-tauri`
|
// 3. tell Vite to ignore watching `src-tauri` and blueprint files
|
||||||
ignored: ["**/src-tauri/**"],
|
ignored: ["**/src-tauri/**", "**/.blueprint/**", "**/CLAUDE.md"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user