git: Fix staging file hunks on Windows (#26661)
Closes #26458 I had checked, and also reference the implementation in vscode. Release Notes: - N/A --------- Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
parent
a02f7e5cda
commit
de67d93a92
1 changed files with 19 additions and 4 deletions
|
@ -10,7 +10,8 @@ use parking_lot::Mutex;
|
|||
use rope::Rope;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::{Borrow, Cow};
|
||||
use std::ffi::OsStr;
|
||||
use std::future;
|
||||
use std::path::Component;
|
||||
use std::process::{ExitStatus, Stdio};
|
||||
|
@ -550,7 +551,7 @@ impl GitRepository for RealGitRepository {
|
|||
.current_dir(&working_directory)
|
||||
.envs(env)
|
||||
.args(["update-index", "--add", "--cacheinfo", "100644", &sha])
|
||||
.arg(path.as_ref())
|
||||
.arg(path.to_unix_style())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
|
@ -565,7 +566,7 @@ impl GitRepository for RealGitRepository {
|
|||
.current_dir(&working_directory)
|
||||
.envs(env)
|
||||
.args(["update-index", "--force-remove"])
|
||||
.arg(path.as_ref())
|
||||
.arg(path.to_unix_style())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
|
@ -779,7 +780,7 @@ impl GitRepository for RealGitRepository {
|
|||
.current_dir(&working_directory?)
|
||||
.envs(env)
|
||||
.args(["update-index", "--add", "--remove", "--"])
|
||||
.args(paths.iter().map(|p| p.as_ref()))
|
||||
.args(paths.iter().map(|p| p.to_unix_style()))
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
|
@ -1336,6 +1337,20 @@ impl RepoPath {
|
|||
|
||||
RepoPath(path.into())
|
||||
}
|
||||
|
||||
pub fn to_unix_style(&self) -> Cow<'_, OsStr> {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use std::ffi::OsString;
|
||||
|
||||
let path = self.0.as_os_str().to_string_lossy().replace("\\", "/");
|
||||
Cow::Owned(OsString::from(path))
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Cow::Borrowed(self.0.as_os_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RepoPath {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue