@@ -198,7 +198,6 @@ fn print_file<P: AsRef<Path>>(
198198 Style::default().paint(" ")
199199 };
200200
201−
202201 match options.style {
203202 // Show only content for plain style
204203 OptionsStyle::Plain => writeln!(
@@ -231,13 +230,16 @@ fn print_file<P: AsRef<Path>>(
231230}
232231
233232fn get_git_diff(filename: &str) -> Option<LineChanges> {
234− let repo = Repository::open_from_env().ok()?;
233+ let repo = Repository::discover(Path::new(&filename)).ok()?;
235234 let workdir = repo.workdir()?;
236− let current_dir = env::current_dir().ok()?;
237− let filepath = current_dir.join(Path::new(&filename));
235+ let absolute_file_path = workdir.join(Path::new(&filename));
236+ let relative_file_path = absolute_file_path.strip_prefix(workdir).ok()?;
238237
239238 let mut diff_options = DiffOptions::new();
240− let pathspec = format!("*{}", filename).into_c_string().ok()?;
239+ let pathspec = format!("*{}", relative_file_path.display())
240+ .into_c_string()
241+ .ok()?;
242+ // GIT pathspec uses relative path
241243 diff_options.pathspec(pathspec);
242244 diff_options.context_lines(0);
243245
@@ -259,7 +261,7 @@ fn get_git_diff(filename: &str) -> Option<LineChanges> {
259261 Some(&mut |delta, hunk| {
260262 let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
261263
262− if filepath != workdir.join(path) {
264+ if relative_file_path != path {
263265 return false;
264266 }
265267