diff options
author | Marcelo Lima <marcelowind@gmail.com> | 2019-11-17 16:15:55 +0100 |
---|---|---|
committer | Marcelo Lima <marcelowind@gmail.com> | 2019-11-17 16:15:55 +0100 |
commit | ee8aee1a5865e4f8670eb1e5d65d23e6265174d7 (patch) | |
tree | 8808f6971eb647052c08fb1461e8f2c38802b566 /src/parse.rs | |
parent | 0052bd7b170188ec30fd1beb5ed89b51c8efbd70 (diff) |
Allow ignoring `git diff` virtual path
Diffstat (limited to 'src/parse.rs')
-rw-r--r-- | src/parse.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/parse.rs b/src/parse.rs index fba0c099..5e5cc5df 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -15,7 +15,7 @@ pub fn get_file_extension_from_diff_line(line: &str) -> Option<&str> { } } -pub fn get_file_path_from_file_meta_line(line: &str) -> String { +pub fn get_file_path_from_file_meta_line(line: &str, remove_prefix: bool) -> String { if line.starts_with("rename") { match line.split(' ').nth(2) { Some(path) => path, @@ -25,7 +25,13 @@ pub fn get_file_path_from_file_meta_line(line: &str) -> String { } else { match line.split(' ').nth(1) { Some("/dev/null") => "/dev/null", - Some(path) => &path[2..], + Some(path) => { + if remove_prefix { + &path[2..] + } else { + path + } + } _ => "", } .to_string() @@ -86,13 +92,25 @@ mod tests { } #[test] + fn test_get_file_path_from_git_file_meta_line() { + assert_eq!( + get_file_path_from_file_meta_line("--- a/src/delta.rs", true), + "src/delta.rs" + ); + assert_eq!( + get_file_path_from_file_meta_line("+++ b/src/delta.rs", true), + "src/delta.rs" + ); + } + + #[test] fn test_get_file_path_from_file_meta_line() { assert_eq!( - get_file_path_from_file_meta_line("--- a/src/delta.rs"), + get_file_path_from_file_meta_line("--- src/delta.rs", false), "src/delta.rs" ); assert_eq!( - get_file_path_from_file_meta_line("+++ b/src/delta.rs"), + get_file_path_from_file_meta_line("+++ src/delta.rs", false), "src/delta.rs" ); } |