Skip to content

submit: omit commit title from GitHub PR body - #1682

Open
VrtxOmega wants to merge 1 commit into
arxanas:masterfrom
VrtxOmega:fix-github-pr-body-title
Open

VrtxOmega wants to merge 1 commit into
arxanas:masterfrom
VrtxOmega:fix-github-pr-body-title

Conversation

@VrtxOmega

Copy link
Copy Markdown

Fixes #1680.

Problem

git branchless submit --forge github uses the commit summary as the GitHub pull request title, but the create and update paths also include the full commit message in the pull request body. For a conventional subject/body commit message, that repeats the subject in the PR description. Projects that squash-merge with title plus body then get the title twice in the final commit message.

Changes

  • Derive the GitHub pull request body from the commit-message body after the summary.
  • Use the same body helper for initial PR creation and later stack metadata updates.
  • Omit the message separator when a commit has no body, leaving only the stack metadata.
  • Add a GitHub forge regression test for a subject plus multi-paragraph body commit.

Verification

  • cargo build -p git-branchless -p git-branchless-submit
  • TEST_GIT="$(which git)" TEST_GIT_EXEC_PATH="$(git --exec-path)" cargo test -p git-branchless-submit test_github_forge --test test_github_forge -- --nocapture
  • cargo fmt --all -- --check

Comment thread git-branchless-submit/src/github.rs Outdated
}
}

fn get_commit_message_body(commit: &Commit<'_>) -> eyre::Result<String> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Instead, can we expose a wrapper for https://docs.rs/git2/latest/git2/struct.Commit.html#method.body? That should be more direct (and less likely to be buggy in case of invalid UTF-8, etc.).

@VrtxOmega
VrtxOmega force-pushed the fix-github-pr-body-title branch from fd89fe9 to 0066918 Compare June 20, 2026 23:36
@VrtxOmega

Copy link
Copy Markdown
Author

Done, thanks. I added a thin Commit::get_body() wrapper around git2::Commit::body() and switched the GitHub PR-body path to use that instead of manually parsing the pretty commit message.

Local verification:

TEST_GIT=$(command -v git) TEST_GIT_EXEC_PATH=$(git --exec-path) cargo test -p git-branchless-submit --tests
cargo fmt --check
git diff --check

When submitting to GitHub, the commit summary is already used as the pull request title. Use the remaining commit message body for both initial creation and stack metadata updates so squash-merge title/body output does not repeat the subject.

Add a forge regression for a subject/body commit and update existing snapshots for subject-only commits.

Fixes arxanas#1680.
@VrtxOmega
VrtxOmega force-pushed the fix-github-pr-body-title branch from 0066918 to b29868c Compare June 20, 2026 23:42

/// Get the commit message body.
#[instrument]
pub fn get_body(&self) -> Option<&str> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, looking at the other wrapper methods, this should also return a BString (and call body_bytes internally). Then, downstream, we should call String::from_utf8_lossy to handle invalid UTF-8 and be sure that we still render something in the PR body.

If body_bytes returns None, then you can propagate the error using the same pattern as for get_summary above.

fn get_commit_message_body(commit: &Commit<'_>) -> String {
let mut body = commit.get_body().unwrap_or_default().to_owned();
if !body.is_empty() && !body.ends_with('\n') {
body.push('\n');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this \n logic is necessary —

  • The docs specify that trailing whitespace is removed, so the check for body.ends_with('\n') is redundant (the only case where this is not true is already handled by body.is_empty()).
  • It might not be obvious, but the calling code uses a multi-line string literal, so it already adds a newline after {commit_message_body}.
  • We can see in the current snapshot tests that the body ends with \n\n, indicating that there's an extra trailing newline.

I think we can remove this function altogether and write a line similar to this one at the call-sites:

            let title = String::from_utf8_lossy(&commit.get_summary()?).into_owned();

but for the body instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title duplicated in pull request body

2 participants