Skip to content

Commit

Permalink
dunce
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Jul 31, 2024
1 parent d6f8ff6 commit 1d6dc32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::cell::RefCell;
use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};

use itertools::Itertools as _;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1d6dc32

Please sign in to comment.