Skip to content

Commit 18e195d

Browse files
author
Stephan Dilly
committed
fixup windows path (#981)
1 parent 3c8eb7e commit 18e195d

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Diff for: asyncgit/src/sync/blame.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ pub struct FileBlame {
3939
pub lines: Vec<(Option<BlameHunk>, String)>,
4040
}
4141

42+
#[cfg(windows)]
43+
fn fixup_windows_path(path: String) -> String {
44+
path.replace("\\", "/")
45+
}
46+
#[cfg(not(windows))]
47+
const fn fixup_windows_path(path: &str) -> &str {
48+
path
49+
}
50+
4251
///
4352
pub fn blame_file(
4453
repo_path: &str,
@@ -50,7 +59,11 @@ pub fn blame_file(
5059

5160
let commit_id = utils::get_head_repo(&repo)?;
5261

53-
let spec = format!("{}:{}", commit_id.to_string(), file_path);
62+
let spec = format!(
63+
"{}:{}",
64+
commit_id.to_string(),
65+
fixup_windows_path(file_path)
66+
);
5467

5568
let object = repo.revparse_single(&spec)?;
5669
let blob = repo.find_blob(object.id())?;
@@ -214,4 +227,24 @@ mod tests {
214227

215228
Ok(())
216229
}
230+
231+
#[test]
232+
fn test_blame_windows_path_dividers() {
233+
let file_path = Path::new("bar\\foo");
234+
let (_td, repo) = repo_init_empty().unwrap();
235+
let root = repo.path().parent().unwrap();
236+
let repo_path = root.as_os_str().to_str().unwrap();
237+
238+
std::fs::create_dir(&root.join("bar")).unwrap();
239+
240+
File::create(&root.join(file_path))
241+
.unwrap()
242+
.write_all(b"line 1\n")
243+
.unwrap();
244+
245+
stage_add_file(repo_path, file_path).unwrap();
246+
commit(repo_path, "first commit").unwrap();
247+
248+
assert!(blame_file(&repo_path, "bar\\foo").is_ok());
249+
}
217250
}

0 commit comments

Comments
 (0)