-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before gitdir: \\?\C:\Users\runneradmin\AppData\Local\Temp\jj-test-fy26a2\second After gitdir: C:/Users/runneradmin/AppData/Local/Temp/jj-test-fy26a2/second And same for the other worktree bits and pieces. We also change the way the tests run git commands, because of yet another error to do with Git being unable to handle verbatim paths: command=`"git" "worktree" "add" "\\\\?\\C:\\Users\\runneradmin\\AppData\\Local\\Temp\\jj-test-ti0MHE\\second"` code=128 stdout="" stderr=``` Preparing worktree (new branch \'second\') fatal: could not create leading directories of \'//?/C:/Users/runneradmin/AppData/Local/Temp/jj-test-ti0MHE/second/.git\': Invalid argument
- Loading branch information
1 parent
da96e63
commit 23f8317
Showing
6 changed files
with
125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//! This is from <https://github.com/rhysd/path-slash>, but tweaked to | ||
//! change any verbatim prefix to non-verbatim, as git does. | ||
//! | ||
//! This is MIT licensed. See lib/LICENSE for a copy of the license. | ||
use std::borrow::Cow; | ||
use std::path::Path; | ||
|
||
#[cfg(target_os = "windows")] | ||
mod windows { | ||
use std::os::windows::ffi::OsStrExt as _; | ||
use std::path::MAIN_SEPARATOR; | ||
|
||
use super::*; | ||
|
||
// Workaround for Windows. There is no way to extract raw byte sequence from | ||
// `OsStr` (in `Path`). And `OsStr::to_string_lossy` may cause extra | ||
// heap allocation. | ||
pub(crate) fn ends_with_main_sep(p: &Path) -> bool { | ||
p.as_os_str().encode_wide().last() == Some(MAIN_SEPARATOR as u16) | ||
} | ||
} | ||
|
||
/// On non-Windows targets, this is just [Path::to_string_lossy]. | ||
/// | ||
/// On Windows targets, this converts backslashes to forward slashes, | ||
/// and removes the `\\?\` verbatim prefix. | ||
#[cfg(not(target_os = "windows"))] | ||
pub fn to_slash_lossy(path: &Path) -> Cow<'_, str> { | ||
path.to_string_lossy() | ||
} | ||
|
||
/// On non-Windows targets, this is just [Path::to_string_lossy]. | ||
/// | ||
/// On Windows targets, this converts backslashes to forward slashes, | ||
/// and removes the `\\?\` verbatim prefix. | ||
#[cfg(target_os = "windows")] | ||
pub fn to_slash_lossy(path: &Path) -> Cow<'_, str> { | ||
use std::path::Component; | ||
use std::path::Prefix; | ||
|
||
let mut buf = String::new(); | ||
for c in path.components() { | ||
match c { | ||
Component::RootDir => { /* empty */ } | ||
Component::CurDir => buf.push('.'), | ||
Component::ParentDir => buf.push_str(".."), | ||
Component::Prefix(prefix_component) => { | ||
match prefix_component.kind() { | ||
Prefix::Disk(disk) | Prefix::VerbatimDisk(disk) => { | ||
if let Some(c) = char::from_u32(disk as u32) { | ||
buf.push(c); | ||
buf.push(':'); | ||
} | ||
} | ||
Prefix::UNC(host, share) | Prefix::VerbatimUNC(host, share) => { | ||
// Write it as non-verbatim but with two forward slashes // instead of | ||
// \\. I think this sounds right? https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/unc-path-recognition-unix | ||
buf.push_str("//"); | ||
buf.push_str(&host.to_string_lossy()); | ||
buf.push_str("/"); | ||
buf.push_str(&share.to_string_lossy()); | ||
} | ||
// Just ignore it and hope for the best? | ||
Prefix::Verbatim(_) => {} | ||
Prefix::DeviceNS(_) => {} | ||
} | ||
// C:\foo is [Prefix, RootDir, Normal]. Avoid C:// | ||
continue; | ||
} | ||
Component::Normal(s) => buf.push_str(&s.to_string_lossy()), | ||
} | ||
buf.push('/'); | ||
} | ||
|
||
if !windows::ends_with_main_sep(path) && buf != "/" && buf.ends_with('/') { | ||
buf.pop(); // Pop last '/' | ||
} | ||
|
||
Cow::Owned(buf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters