-
Notifications
You must be signed in to change notification settings - Fork 5
Fix: Improve merge commit information retrieval #42
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
base: master
Are you sure you want to change the base?
Conversation
The `get_merge_commit_info` function was previously only checking the latest commit on a branch for merge information. This could lead to incomplete or misleading reports if earlier merge commits existed on the branch. This commit modifies `get_merge_commit_info` to iterate through all commits on the specified branch. It now correctly identifies all merge commits that merged from the given parent branch and extracts their respective commit messages and statistics. Additionally, a new test case (`test_get_merge_commit_info_multiple_merges`) has been added to `tests/merge.rs`. This test verifies that the updated function correctly retrieves information for multiple merge commits on a single branch, ensuring more robust and accurate reporting of merge activities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances get_merge_commit_info
to scan all commits on a branch for merge commits from a given parent branch and adds a test to verify multiple merges are detected.
- Iterate through all commit hashes instead of only the latest
- Refine parsing of merge messages and stats, collecting multiple
MergeCommitInfo
- Add
test_get_merge_commit_info_multiple_merges
to cover multiple merge scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/merge.rs | Added a new test to validate multiple merge commit retrieval |
src/main.rs | Overhauled get_merge_commit_info to loop commits and aggregate merge info |
// A merge commit must have a line starting with "Merge: " | ||
let is_actual_merge_commit = commit_lines.iter().any(|line| line.starts_with("Merge: ")); | ||
|
||
if let Some(files_idx) = line.find("file changed") { | ||
if let Some(files_num) = line[..files_idx].split_whitespace().last() { | ||
files_changed = files_num.parse().unwrap_or(0); | ||
} | ||
} else if let Some(files_idx) = line.find("files changed") { | ||
if let Some(files_num) = line[..files_idx].split_whitespace().last() { | ||
files_changed = files_num.parse().unwrap_or(0); | ||
} | ||
} | ||
if is_actual_merge_commit && (is_merge_from_parent || (parent_branch.is_empty() && is_generic_merge)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detection currently only matches messages starting with "Merge branch...". Custom merge messages (e.g., from -m
) won’t be recognized. Consider checking the commit’s parent count or using git log --merges
to reliably identify merge commits.
// A merge commit must have a line starting with "Merge: " | |
let is_actual_merge_commit = commit_lines.iter().any(|line| line.starts_with("Merge: ")); | |
if let Some(files_idx) = line.find("file changed") { | |
if let Some(files_num) = line[..files_idx].split_whitespace().last() { | |
files_changed = files_num.parse().unwrap_or(0); | |
} | |
} else if let Some(files_idx) = line.find("files changed") { | |
if let Some(files_num) = line[..files_idx].split_whitespace().last() { | |
files_changed = files_num.parse().unwrap_or(0); | |
} | |
} | |
if is_actual_merge_commit && (is_merge_from_parent || (parent_branch.is_empty() && is_generic_merge)) { | |
// A merge commit is identified by having more than one parent. | |
let is_actual_merge_commit = commit.parent_count() > 1; | |
if is_actual_merge_commit { |
Copilot uses AI. Check for mistakes.
let mut command = Command::new("git"); | ||
command.args(["log", "--oneline", "-1", branch_name]); | ||
command.args(["log", "--format=%H", branch_name]); // Get only commit hashes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running git show
on every commit can be slow. You could use git log --merges --format=%H <branch>
to directly list merge commits and avoid iterating non-merge commits.
command.args(["log", "--format=%H", branch_name]); // Get only commit hashes | |
command.args(["log", "--merges", "--format=%H", branch_name]); // Get only merge commit hashes |
Copilot uses AI. Check for mistakes.
The
get_merge_commit_info
function was previously only checking the latest commit on a branch for merge information. This could lead to incomplete or misleading reports if earlier merge commits existed on the branch.This commit modifies
get_merge_commit_info
to iterate through all commits on the specified branch. It now correctly identifies all merge commits that merged from the given parent branch and extracts their respective commit messages and statistics.Additionally, a new test case (
test_get_merge_commit_info_multiple_merges
) has been added totests/merge.rs
. This test verifies that the updated function correctly retrieves information for multiple merge commits on a single branch, ensuring more robust and accurate reporting of merge activities.