Skip to content

Fix file diff filename extraction #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ impl SplitPrefixInclusive for str {
///
/// If the diff is not of the expected form, then None is returned.
pub(crate) fn get_file_name_from_diff(file_diff: &str) -> Option<&str> {
let (_, suffix) = file_diff.split_once("diff --git a/")?;
let (file_name, _) = suffix.split_once(' ')?;
Some(file_name)
let (_, suffix) = file_diff.split_once("diff --git ")?;
let mut parts = suffix.split_whitespace();
let _old = parts.next()?;
let new = parts.next()?;
new.strip_prefix("b/")
}

#[cfg(test)]
Expand Down Expand Up @@ -85,5 +87,12 @@ index 0000000..a51b2a6
),
Some("foo")
);

assert_eq!(
get_file_name_from_diff(
"diff --git a/old_name b/new_name\n--- a/old_name\n+++ b/new_name"
),
Some("new_name")
);
}
}
Loading