From 1d6dc32bbd18729ef43feb56f0b234832e0a520d Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Tue, 30 Jul 2024 23:34:36 -0700 Subject: [PATCH] dunce --- cli/tests/common/mod.rs | 13 ++++++++++--- lib/src/git.rs | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/tests/common/mod.rs b/cli/tests/common/mod.rs index 32ce520b7f..c028923fd2 100644 --- a/cli/tests/common/mod.rs +++ b/cli/tests/common/mod.rs @@ -14,6 +14,7 @@ use std::cell::RefCell; use std::collections::HashMap; +use std::fs; use std::path::{Path, PathBuf}; use itertools::Itertools as _; @@ -54,7 +55,7 @@ impl Default for TestEnvironment { testutils::hermetic_libgit2(); let tmp_dir = testutils::new_temp_dir(); - let env_root = tmp_dir.path().canonicalize().unwrap(); + let env_root = dunce::canonicalize(tmp_dir.path()).unwrap(); let home_dir = env_root.join("home"); std::fs::create_dir(&home_dir).unwrap(); let config_dir = env_root.join("config"); @@ -321,9 +322,15 @@ impl TestEnvironment { pub fn normalize_output(&self, text: &str) -> String { let text = text.replace("jj.exe", "jj"); let regex = Regex::new(&format!( - r"({}|{})(\S+)", + r"({}|{}|{})(\S+)", regex::escape(&self.env_root.display().to_string()), - regex::escape(&self.env_root.to_slash_lossy()) + regex::escape(&self.env_root.to_slash_lossy()), + regex::escape( + &fs::canonicalize(&self.env_root) + .unwrap() + .display() + .to_string() + ) )) .unwrap(); regex diff --git a/lib/src/git.rs b/lib/src/git.rs index f1e2d6a38d..01714c4de5 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -1165,6 +1165,7 @@ pub fn sanitize_git_url_if_path(cwd: &Path, source: &str) -> String { // TODO: This won't work for Windows UNC path or (less importantly) if the // original source is a non-UTF Windows path. For Windows UNC paths, we // could use dunce, though see also https://gitlab.com/kornelski/dunce/-/issues/7 + // TODO: double-check about UNC paths; what does Git do? cwd.join(source).to_slash().map_or_else( // It's less likely that cwd isn't utf-8, so just fall back to original source. || source.to_owned(),