Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Windows: a workspace raea 0.1.5 or 0.1.6 broke is repaired. Its include.path named a \\?\ path Git for Windows can't open, so every git command in it failed, rev-parse too, and raea workspace init inside it, adopt and doctor --fix all stopped there (#169). include() now drops such a line from the repo's config file itself before asking git (apps/workspace/src/repair.rs), and raea doctor says so. Tested on Windows 11, Git for Windows 2.49: git fails in the broken repo, then works after the repair.

shinyobjectzb54136c4afb6
diff --git a/apps/workspace/src/doctor.rs b/apps/workspace/src/doctor.rs
index 922eab26..7f51a7e4 100644
--- a/apps/workspace/src/doctor.rs
+++ b/apps/workspace/src/doctor.rs
@@ -49,6 +49,11 @@ fn old_briefs(dir: &Path, depth: usize, out: &mut Vec<Finding>) {
/// A committed git-config file's keys this version writes, and its include from the repo's config.
fn format(repo: &Path, file: &Path, keys: &[(&str, String)], out: &mut Vec<Finding>) {
+ // first, so its fix runs before the others: with it there, every git command in the repo fails (#169)
+ if crate::repair::has_verbatim_include(repo) {
+ let says = format!("{}: its git config includes a \\\\?\\ path Git for Windows can't open (written by raea 0.1.5 or 0.1.6 on Windows), so every git command in it fails; --fix replaces it", repo.display());
+ out.push(Finding { says, fix: Fix::Include(repo.to_path_buf(), file.to_path_buf()) });
+ }
for (k, v) in keys {
if get(file, k).is_none() {
out.push(Finding { says: format!("{}: no {k} (an older format); --fix sets it to {v}", file.display()), fix: Fix::Set(file.to_path_buf(), k.to_string(), v.clone()) });
diff --git a/apps/workspace/src/lib.rs b/apps/workspace/src/lib.rs
index dc350281..bc157645 100644
--- a/apps/workspace/src/lib.rs
+++ b/apps/workspace/src/lib.rs
@@ -8,6 +8,7 @@ use serde_json::json;
mod controllers;
pub mod doctor;
mod literal;
+mod repair;
pub mod next;
pub mod registry;
mod storage;
diff --git a/apps/workspace/src/repair.rs b/apps/workspace/src/repair.rs
new file mode 100644
index 00000000..be36f24f
--- /dev/null
+++ b/apps/workspace/src/repair.rs
@@ -0,0 +1,58 @@
+//! Workspaces raea 0.1.5 and 0.1.6 broke on Windows (#169): their include.path is a relative climb glued to a `\\?\`
+//! path (`../../../../\\?\C:/\/Users/...`), which Git for Windows can't open, so every git command in the repo failed
+//! with "Invalid argument", `git rev-parse` too. A repair can't ask git, then: it reads the repo's config file itself
+//! and drops those lines, and the include is added again the right way (workspace::include, run by `raea workspace
+//! init` inside it, `raea workspace adopt` and `raea doctor --fix`).
+
+use std::path::{Path, PathBuf};
+
+/// The repo's own config file, found without git: `.git/config`, or the config in the folder a `.git` file names (a
+/// submodule's, under the workspace's .git/modules).
+fn config_file(repo: &Path) -> Option<PathBuf> {
+ let dot = repo.join(".git");
+ if dot.is_dir() {
+ return Some(dot.join("config"));
+ }
+ let text = std::fs::read_to_string(&dot).ok()?;
+ let dir = PathBuf::from(text.lines().find_map(|l| l.strip_prefix("gitdir:"))?.trim());
+ Some(if dir.is_absolute() { dir } else { repo.join(dir) }.join("config"))
+}
+
+/// The config's text without the `path = ...\\?\...` lines of its [include] sections, and whether there were any.
+/// [includeIf] sections and every other line are kept as they are.
+pub(crate) fn without_verbatim(text: &str) -> (String, bool) {
+ let mut section = String::new();
+ let mut dropped = false;
+ let eol = if text.contains("\r\n") { "\r\n" } else { "\n" };
+ let kept: Vec<&str> = text
+ .lines()
+ .filter(|l| {
+ let t = l.trim();
+ if t.starts_with('[') {
+ section = t.trim_start_matches('[').split(']').next().unwrap_or_default().trim().to_ascii_lowercase();
+ return true;
+ }
+ let key = t.split('=').next().unwrap_or_default().trim();
+ let bad = section == "include" && key.eq_ignore_ascii_case("path") && t.contains("?\\");
+ dropped |= bad;
+ !bad
+ })
+ .collect();
+ (kept.join(eol) + eol, dropped)
+}
+
+/// Whether the repo's config holds an include git can't open on Windows (what `raea doctor` reports).
+pub fn has_verbatim_include(repo: &Path) -> bool {
+ config_file(repo).and_then(|c| std::fs::read_to_string(c).ok()).is_some_and(|t| without_verbatim(&t).1)
+}
+
+/// Drops those includes from the repo's config. Ok(true) when there were some.
+pub(crate) fn drop_verbatim_includes(repo: &Path) -> Result<bool, String> {
+ let Some(cfg) = config_file(repo) else { return Ok(false) };
+ let Ok(text) = std::fs::read_to_string(&cfg) else { return Ok(false) };
+ let (fixed, dropped) = without_verbatim(&text);
+ if dropped {
+ std::fs::write(&cfg, fixed).map_err(|e| format!("{}: {e}", cfg.display()))?;
+ }
+ Ok(dropped)
+}
diff --git a/apps/workspace/src/tests.rs b/apps/workspace/src/tests.rs
index b7463d6b..22c5cb54 100644
--- a/apps/workspace/src/tests.rs
+++ b/apps/workspace/src/tests.rs
@@ -203,3 +203,39 @@ fn a_new_workspace_and_project_have_the_layout() {
assert!(tracked.contains("projects/desk-test/components/.gitkeep") && tracked.contains("shared/assets/.gitkeep"), "{tracked}");
let _ = std::fs::remove_dir_all(&ws);
}
+
+#[test]
+fn a_verbatim_include_is_dropped_and_nothing_else() {
+ // .git/config as raea 0.1.6 left it on Windows (#169, read off the test PC), with an [includeIf] and a good include
+ let text = "[core]\n\trepositoryformatversion = 0\n[include]\n\tpath = ../../../../../../../../\\\\\\\\?\\\\C:/\\\\/Users/you/Documents/raea/acme/.raea/workspace\n[includeIf \"gitdir:~/x/\"]\n\tpath = ../keep?\\\\x\n[include]\n\tpath = ../.raea/workspace\n";
+ let (fixed, dropped) = crate::repair::without_verbatim(text);
+ assert!(dropped);
+ assert_eq!(fixed, "[core]\n\trepositoryformatversion = 0\n[include]\n[includeIf \"gitdir:~/x/\"]\n\tpath = ../keep?\\\\x\n[include]\n\tpath = ../.raea/workspace\n");
+ assert_eq!(crate::repair::without_verbatim(&fixed).0, fixed);
+ assert!(!crate::repair::without_verbatim("[include]\r\n\tpath = ../.raea/workspace\r\n").1);
+}
+
+#[test]
+fn a_workspace_0_1_6_broke_is_repaired() {
+ // updated from 0.1.6: its include names a \\?\ path; doctor says so, and adopt (as init inside it) puts it right
+ let ws = scratch("repair");
+ crate::workspace::workspace(&["adopt".into(), ws.display().to_string(), "--name".into(), "Repair".into()]).unwrap();
+ let cfg = ws.join(".git/config");
+ let bad = "\tpath = ../../../../\\\\\\\\?\\\\C:/\\\\/Users/you/Documents/raea/repair/.raea/workspace\n";
+ let text = std::fs::read_to_string(&cfg).unwrap().replace("\tpath = ../.raea/workspace\n", bad);
+ std::fs::write(&cfg, text).unwrap();
+ // on Windows this is #169 itself: Git for Windows refuses the include, so every git command in the repo fails
+ let status = || std::process::Command::new("git").arg("-C").arg(&ws).args(["status", "--short"]).output().unwrap();
+ if cfg!(windows) {
+ assert!(!status().status.success(), "git ran in a repo whose include names a \\\\?\\ path");
+ }
+ assert!(crate::repair::has_verbatim_include(&ws));
+ let said: Vec<String> = crate::doctor::findings(&ws, &[], "test").into_iter().filter(|f| f.fixable()).map(|f| f.says).collect();
+ assert!(said.iter().any(|s| s.contains("Git for Windows can't open")), "{said:?}");
+ crate::workspace::workspace(&["adopt".into(), ws.display().to_string()]).unwrap();
+ assert!(!crate::repair::has_verbatim_include(&ws));
+ let o = std::process::Command::new("git").arg("-C").arg(&ws).args(["config", "--get-all", "include.path"]).output().unwrap();
+ assert_eq!(String::from_utf8_lossy(&o.stdout).trim(), "../.raea/workspace");
+ assert!(status().status.success(), "git status after the repair: {}", String::from_utf8_lossy(&status().stderr));
+ let _ = std::fs::remove_dir_all(&ws);
+}
diff --git a/apps/workspace/src/workspace.rs b/apps/workspace/src/workspace.rs
index 7ba7d6ab..80d1b76d 100644
--- a/apps/workspace/src/workspace.rs
+++ b/apps/workspace/src/workspace.rs
@@ -120,7 +120,9 @@ pub fn default_root(home: &Path) -> PathBuf {
pub(crate) fn include(repo: &Path, file: &Path) -> R<()> {
// both ends the same way, plain (dunce): on Windows git prints C:/... and canonicalize() alone gave \\?\C:\..., which
// share no root, so the include climbed to the drive and named the file by its \\?\ path, and every git command in
- // the workspace failed ("Invalid argument") from its first commit (0.1.5, 0.1.6)
+ // the workspace failed ("Invalid argument") from its first commit (0.1.5, 0.1.6). Such an include goes first: with
+ // it there, the rev-parse below fails too.
+ crate::repair::drop_verbatim_includes(repo)?;
let cfg = PathBuf::from(git(repo, &["rev-parse", "--path-format=absolute", "--git-path", "config"])?);
let cfg = dunce::canonicalize(&cfg).unwrap_or(cfg);
let file = dunce::canonicalize(file).map_err(|e| format!("{}: {e}", file.display()))?;