@@ -230,16 +230,12 @@ fn print_file<P: AsRef<Path>>(
230230}
231231
232232fn get_git_diff(filename: &str) -> Option<LineChanges> {
233− let repo = Repository::discover(Path::new(&filename)).ok()?;
234− let workdir = repo.workdir()?;
235− let absolute_file_path = workdir.join(Path::new(&filename));
236− let relative_file_path = absolute_file_path.strip_prefix(workdir).ok()?;
233+ let repo = Repository::discover(&filename).ok()?;
234+ let path_absolute = fs::canonicalize(&filename).ok()?;
235+ let path_relative_to_repo = path_absolute.strip_prefix(repo.workdir()?).ok()?;
237236
238237 let mut diff_options = DiffOptions::new();
239− let pathspec = format!("*{}", relative_file_path.display())
240− .into_c_string()
241− .ok()?;
242− // GIT pathspec uses relative path
238+ let pathspec = path_relative_to_repo.into_c_string().ok()?;
243239 diff_options.pathspec(pathspec);
244240 diff_options.context_lines(0);
245241
@@ -261,7 +257,7 @@ fn get_git_diff(filename: &str) -> Option<LineChanges> {
261257 Some(&mut |delta, hunk| {
262258 let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
263259
264− if relative_file_path != path {
260+ if path_relative_to_repo != path {
265261 return false;
266262 }
267263