Skip to content

Commit a55dcf6

Browse files
author
Stephan Dilly
authored
blame: fixup windows paths (#984)
closes #981
1 parent 3c8eb7e commit a55dcf6

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Fixed
1818
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))
1919
- improved file diff speed dramatically ([#976](https://github.com/extrawurst/gitui/issues/976))
20+
- blaming files in sub-folders on windows ([#981](https://github.com/extrawurst/gitui/issues/981))
2021

2122
## [0.18] - 2021-10-11
2223

asyncgit/src/sync/blame.rs

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

42+
/// fixup `\` windows path seperators to git compatible `/`
43+
fn fixup_windows_path(path: &str) -> String {
44+
#[cfg(windows)]
45+
{
46+
path.replace("\\", "/")
47+
}
48+
49+
#[cfg(not(windows))]
50+
{
51+
path.to_string()
52+
}
53+
}
54+
4255
///
4356
pub fn blame_file(
4457
repo_path: &str,
@@ -50,7 +63,11 @@ pub fn blame_file(
5063

5164
let commit_id = utils::get_head_repo(&repo)?;
5265

53-
let spec = format!("{}:{}", commit_id.to_string(), file_path);
66+
let spec = format!(
67+
"{}:{}",
68+
commit_id.to_string(),
69+
fixup_windows_path(file_path)
70+
);
5471

5572
let object = repo.revparse_single(&spec)?;
5673
let blob = repo.find_blob(object.id())?;
@@ -214,4 +231,24 @@ mod tests {
214231

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

0 commit comments

Comments
 (0)