Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 38 additions & 1 deletion asyncgit/src/sync/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ pub struct FileBlame {
pub lines: Vec<(Option<BlameHunk>, 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,
Expand All @@ -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())?;
Expand Down Expand Up @@ -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());
}
}