diff --git a/CHANGELOG.md b/CHANGELOG.md index a67f39da..d94cfbe6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933)) - improved file diff speed dramatically ([#976](https://github.com/extrawurst/gitui/issues/976)) +- blaming files in sub-folders on windows ([#981](https://github.com/extrawurst/gitui/issues/981)) ## [0.18] - 2021-10-11 diff --git a/asyncgit/src/sync/blame.rs b/asyncgit/src/sync/blame.rs index 8a3aaed2..c9e3c1c6 100644 --- a/asyncgit/src/sync/blame.rs +++ b/asyncgit/src/sync/blame.rs @@ -39,6 +39,19 @@ pub struct FileBlame { pub lines: Vec<(Option, String)>, } +/// fixup `\` windows path seperators to git compatible `/` +fn fixup_windows_path(path: &str) -> String { + #[cfg(windows)] + { + path.replace("\\", "/") + } + + #[cfg(not(windows))] + { + path.to_string() + } +} + /// pub fn blame_file( repo_path: &str, @@ -50,7 +63,11 @@ pub fn blame_file( let commit_id = utils::get_head_repo(&repo)?; - let spec = format!("{}:{}", commit_id.to_string(), file_path); + let spec = format!( + "{}:{}", + commit_id.to_string(), + fixup_windows_path(file_path) + ); let object = repo.revparse_single(&spec)?; let blob = repo.find_blob(object.id())?; @@ -214,4 +231,24 @@ mod tests { Ok(()) } + + #[test] + fn test_blame_windows_path_dividers() { + let file_path = Path::new("bar\\foo"); + let (_td, repo) = repo_init_empty().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + std::fs::create_dir(&root.join("bar")).unwrap(); + + File::create(&root.join(file_path)) + .unwrap() + .write_all(b"line 1\n") + .unwrap(); + + stage_add_file(repo_path, file_path).unwrap(); + commit(repo_path, "first commit").unwrap(); + + assert!(blame_file(&repo_path, "bar\\foo").is_ok()); + } }