Skip to content

Fix generated branch names containing invalid dot sequences - #80

Merged
rm3l merged 2 commits into
mainfrom
23-generated-branch-name-might-be-invalid-for-git
Oct 18, 2026
Merged

rm3l merged 2 commits into
mainfrom
23-generated-branch-name-might-be-invalid-for-git

Conversation

@rm3l

@rm3l rm3l commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Dots in issue titles (e.g. trailing ...) produced branch names with .. or trailing ., which Git rejects as invalid ref names.
  • Changed TrimSuffix to TrimRight so all trailing dots are stripped, not just one.
  • Removed . from the allowed-character regex so dots are replaced with - like other punctuation.

Fixes #23

Test plan

  • Added test case reproducing the reported issue ("Collect metrics for issues, pull requests, ...")
  • Added test case for dots within titles ("Fix v2.0 regression")
  • Added test case for dots-only titles ("...")
  • All existing tests continue to pass

🤖 Generated with Claude Code

Summary by Sourcery

Generate Git-valid branch names from titles containing dots and punctuation.

Bug Fixes:

  • Prevent generated branch names from containing invalid dot sequences or trailing punctuation.
  • Ensure truncated branch names do not end with a replacement hyphen.

Enhancements:

  • Normalize dots consistently by replacing embedded dots and removing all trailing dots before branch name generation.

Tests:

  • Add coverage for trailing dots, embedded dots, dots-only titles, and truncation without a trailing hyphen.

Dots in issue titles (e.g. trailing "...") produced branch names with
".." or trailing ".", which Git rejects. Strip all trailing dots with
TrimRight instead of only one with TrimSuffix, and exclude dots from
the allowed-character regex so they are replaced like other punctuation.

Fixes #23

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates branch-name sanitization so dots are treated as punctuation and all trailing dots are removed, preventing invalid Git refs, with focused regression tests for trailing, embedded, and dot-only title inputs.

File-Level Changes

Change Details Files
Normalize dots in generated branch names to prevent invalid Git ref sequences and trailing dots.
  • Replace runs of non-alphanumeric characters, including dots, with hyphens.
  • Strip all trailing dots before normalization rather than removing only one.
  • Reject titles consisting solely of dots after suffix cleanup.
pkg/branch/branch.go
Add regression coverage for trailing, embedded, and dot-only titles.
  • Verify multiple trailing dots are removed from the generated name.
  • Verify dots inside titles become hyphens.
  • Verify dot-only titles return an error.
pkg/branch/branch_test.go

Assessment against linked issues

Issue Objective Addressed Explanation
#23 Generate Git-valid branch names when issue titles contain repeated or trailing dots. ✅
#23 Normalize dots within titles so they are replaced rather than retained in the generated branch name. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Truncating a generated branch name at maxLen could leave a trailing
hyphen. Trim it so the result is always clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rm3l
rm3l merged commit 36e3d90 into main Oct 18, 2026
6 checks passed
@rm3l
rm3l deleted the 23-generated-branch-name-might-be-invalid-for-git branch October 18, 2026 21:21
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.

Generated branch name might be invalid for Git

1 participant