mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 02:01:05 +00:00
Fix bug where git modification markers would not be shown if directory
was not cwd Git ignore Idea dir Fix #22
This commit is contained in:
parent
418b3c5ea1
commit
cbdf5c50c4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
/target/
|
/target/
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
.idea
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -198,7 +198,6 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
Style::default().paint(" ")
|
Style::default().paint(" ")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
match options.style {
|
match options.style {
|
||||||
// Show only content for plain style
|
// Show only content for plain style
|
||||||
OptionsStyle::Plain => writeln!(
|
OptionsStyle::Plain => writeln!(
|
||||||
@ -231,13 +230,16 @@ fn print_file<P: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
||||||
let repo = Repository::open_from_env().ok()?;
|
let repo = Repository::discover(Path::new(&filename)).ok()?;
|
||||||
let workdir = repo.workdir()?;
|
let workdir = repo.workdir()?;
|
||||||
let current_dir = env::current_dir().ok()?;
|
let absolute_file_path = workdir.join(Path::new(&filename));
|
||||||
let filepath = current_dir.join(Path::new(&filename));
|
let relative_file_path = absolute_file_path.strip_prefix(workdir).ok()?;
|
||||||
|
|
||||||
let mut diff_options = DiffOptions::new();
|
let mut diff_options = DiffOptions::new();
|
||||||
let pathspec = format!("*{}", filename).into_c_string().ok()?;
|
let pathspec = format!("*{}", relative_file_path.display())
|
||||||
|
.into_c_string()
|
||||||
|
.ok()?;
|
||||||
|
// GIT pathspec uses relative path
|
||||||
diff_options.pathspec(pathspec);
|
diff_options.pathspec(pathspec);
|
||||||
diff_options.context_lines(0);
|
diff_options.context_lines(0);
|
||||||
|
|
||||||
@ -259,7 +261,7 @@ fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
|||||||
Some(&mut |delta, hunk| {
|
Some(&mut |delta, hunk| {
|
||||||
let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
|
let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
|
||||||
|
|
||||||
if filepath != workdir.join(path) {
|
if relative_file_path != path {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user