Skip to content

Commit 757c043

Browse files
authored
Fix git features not working when a Windows host collaborates with a unix guest (zed-industries#43515)
We were using `std::path::Path::strip_prefix` to determine which repository an absolute path belongs to, which doesn't work when the paths are Windows-style but the code is running on unix. Replace it with a platform-agnostic implementation of `strip_prefix`. Release Notes: - Fixed git features not working when a Windows host collaborates with a unix guest
1 parent 57e1bb8 commit 757c043

File tree

15 files changed

+159
-30
lines changed

15 files changed

+159
-30
lines changed

crates/agent_ui/src/acp/message_editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ mod tests {
14231423
rel_path("b/eight.txt"),
14241424
];
14251425

1426-
let slash = PathStyle::local().separator();
1426+
let slash = PathStyle::local().primary_separator();
14271427

14281428
let mut opened_editors = Vec::new();
14291429
for path in paths {

crates/agent_ui/src/acp/thread_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3989,7 +3989,7 @@ impl AcpThreadView {
39893989
let file = buffer.read(cx).file()?;
39903990
let path = file.path();
39913991
let path_style = file.path_style(cx);
3992-
let separator = file.path_style(cx).separator();
3992+
let separator = file.path_style(cx).primary_separator();
39933993

39943994
let file_path = path.parent().and_then(|parent| {
39953995
if parent.is_empty() {

crates/file_finder/src/file_finder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ impl FileFinderDelegate {
10601060
(
10611061
filename.to_string(),
10621062
Vec::new(),
1063-
prefix.display(path_style).to_string() + path_style.separator(),
1063+
prefix.display(path_style).to_string() + path_style.primary_separator(),
10641064
Vec::new(),
10651065
)
10661066
} else {
@@ -1071,7 +1071,7 @@ impl FileFinderDelegate {
10711071
.map_or(String::new(), |f| f.to_string_lossy().into_owned()),
10721072
Vec::new(),
10731073
entry_path.absolute.parent().map_or(String::new(), |path| {
1074-
path.to_string_lossy().into_owned() + path_style.separator()
1074+
path.to_string_lossy().into_owned() + path_style.primary_separator()
10751075
}),
10761076
Vec::new(),
10771077
)

crates/file_finder/src/file_finder_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ async fn test_history_match_positions(cx: &mut gpui::TestAppContext) {
15981598
assert_eq!(file_label.highlight_indices(), &[0, 1, 2]);
15991599
assert_eq!(
16001600
path_label.text(),
1601-
format!("test{}", PathStyle::local().separator())
1601+
format!("test{}", PathStyle::local().primary_separator())
16021602
);
16031603
assert_eq!(path_label.highlight_indices(), &[] as &[usize]);
16041604
});

crates/file_finder/src/open_path_prompt.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl PickerDelegate for OpenPathDelegate {
559559
parent_path,
560560
candidate.path.string,
561561
if candidate.is_dir {
562-
path_style.separator()
562+
path_style.primary_separator()
563563
} else {
564564
""
565565
}
@@ -569,7 +569,7 @@ impl PickerDelegate for OpenPathDelegate {
569569
parent_path,
570570
candidate.path.string,
571571
if candidate.is_dir {
572-
path_style.separator()
572+
path_style.primary_separator()
573573
} else {
574574
""
575575
}
@@ -826,7 +826,13 @@ impl PickerDelegate for OpenPathDelegate {
826826
}
827827

828828
fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str> {
829-
Arc::from(format!("[directory{}]filename.ext", self.path_style.separator()).as_str())
829+
Arc::from(
830+
format!(
831+
"[directory{}]filename.ext",
832+
self.path_style.primary_separator()
833+
)
834+
.as_str(),
835+
)
830836
}
831837

832838
fn separators_after_indices(&self) -> Vec<usize> {

crates/fuzzy/src/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn match_fixed_path_set(
107107
.display(path_style)
108108
.chars()
109109
.collect::<Vec<_>>();
110-
path_prefix_chars.extend(path_style.separator().chars());
110+
path_prefix_chars.extend(path_style.primary_separator().chars());
111111
let lowercase_pfx = path_prefix_chars
112112
.iter()
113113
.map(|c| c.to_ascii_lowercase())

crates/git_ui/src/git_panel.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,8 +4351,11 @@ impl GitPanel {
43514351
.when(strikethrough, Label::strikethrough),
43524352
),
43534353
(true, false) => this.child(
4354-
self.entry_label(format!("{dir}{}", path_style.separator()), path_color)
4355-
.when(strikethrough, Label::strikethrough),
4354+
self.entry_label(
4355+
format!("{dir}{}", path_style.primary_separator()),
4356+
path_color,
4357+
)
4358+
.when(strikethrough, Label::strikethrough),
43564359
),
43574360
_ => this,
43584361
}

crates/project/src/git_store.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,10 +3222,8 @@ impl RepositorySnapshot {
32223222
abs_path: &Path,
32233223
path_style: PathStyle,
32243224
) -> Option<RepoPath> {
3225-
abs_path
3226-
.strip_prefix(&work_directory_abs_path)
3227-
.ok()
3228-
.and_then(|path| RepoPath::from_std_path(path, path_style).ok())
3225+
let rel_path = path_style.strip_prefix(abs_path, work_directory_abs_path)?;
3226+
Some(RepoPath::from_rel_path(&rel_path))
32293227
}
32303228

32313229
pub fn had_conflict_on_last_merge_head_change(&self, repo_path: &RepoPath) -> bool {

crates/project/src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ impl DirectoryLister {
927927
.map(|worktree| worktree.read(cx).abs_path().to_string_lossy().into_owned())
928928
.or_else(|| std::env::home_dir().map(|dir| dir.to_string_lossy().into_owned()))
929929
.map(|mut s| {
930-
s.push_str(path_style.separator());
930+
s.push_str(path_style.primary_separator());
931931
s
932932
})
933933
.unwrap_or_else(|| {

crates/project_panel/src/project_panel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4837,7 +4837,7 @@ impl ProjectPanel {
48374837
.collect::<Vec<_>>();
48384838
let active_index = folded_ancestors.active_index();
48394839
let components_len = components.len();
4840-
let delimiter = SharedString::new(path_style.separator());
4840+
let delimiter = SharedString::new(path_style.primary_separator());
48414841
for (index, component) in components.iter().enumerate() {
48424842
if index != 0 {
48434843
let delimiter_target_index = index - 1;

0 commit comments

Comments
 (0)