@@ -120,9 +120,13 @@ fn print_file<P: AsRef<Path>>(
120120
121121fn get_git_diff(filename: String) -> Option<LineChanges> {
122122 let repo = Repository::open_from_env().ok()?;
123+ let workdir = repo.workdir()?;
124+ let current_dir = env::current_dir().ok()?;
125+ let filepath = current_dir.join(Path::new(&filename));
123126
124127 let mut diff_options = DiffOptions::new();
125− diff_options.pathspec(filename.into_c_string().ok()?);
128+ let pathspec = format!("*{}", filename).into_c_string().ok()?;
129+ diff_options.pathspec(pathspec);
126130 diff_options.context_lines(0);
127131
128132 let diff = repo.diff_index_to_workdir(None, Some(&mut diff_options))
@@ -140,7 +144,13 @@ fn get_git_diff(filename: String) -> Option<LineChanges> {
140144 let _ = diff.foreach(
141145 &mut |_, _| true,
142146 None,
143− Some(&mut |_, hunk| {
147+ Some(&mut |delta, hunk| {
148+ let path = delta.new_file().path().unwrap_or(Path::new(""));
149+
150+ if filepath != workdir.join(path) {
151+ return false;
152+ }
153+
144154 let old_lines = hunk.old_lines();
145155 let new_start = hunk.new_start();
146156 let new_lines = hunk.new_lines();