Repository navigation
Skip the ReplaceBranch prefix when the message already starts with it - #930
Open
NikitaNazarov1 wants to merge 1 commit into
Open
NikitaNazarov1 wants to merge 1 commit into
NikitaNazarov1 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#875 asks for a hook that copies a ticket ID from a branch such as
task/PROJ-123/fix-logininto the commit message as[PROJ-123].ReplaceBranchcan already do this withbranch_patternandreplacement_text. But with the defaultskipped_commit_types, it runs only for editor commits. When you removemessageorcommitfrom that list, the hook adds a second prefix togit commit -m '[PROJ-123] Fix'and togit commit --amend. It also prefixesgit commit --fixup, so the subject no longer starts withfixup!andgit rebase --autosquashdoes not find the commit.Leave the message unchanged when it already starts with the replacement text, or with
fixup!,squash!, oramend!. The comparison ignores surrounding whitespace, so[PROJ-123]Fixalso counts. A template that ends in a word character must end at a word boundary:PROJ-12does not matchPROJ-123 Fix. The comparison uses bytes, becauselstripraises on a message that is not valid in the default encoding, such as an amended Latin-1 commit, and that would stop the commit. A whitespace-only replacement text is still prepended as before.The default configuration does not change: it runs the hook only for editor commits, whose message file starts with a blank line and Git comments.
Document a ticket ID configuration in the hook's class comment. It keeps
templateskipped, because a commit template can start with a#line, and the prefix would turn that comment into the subject. It setson_warn: pass, so branches without a ticket ID do not show a warning.Follow-up to #875, where a PR with a configurable hook was invited.
Validation:
bundle exec ruby script/parallel_rspec.rbpasses all 1884 examples, and RuboCop reports no offenses on the changed files. 8 of the newReplaceBranchexamples fail againstmain. The others pin behavior that must not change: a longer ticket ID, a whitespace-only template, and a message that is not valid UTF-8. I also ran the documented configuration in a disposable repository with Git 2.50.1:commit -m 'Fix login'gives[PROJ-123] Fix login.--amend -m '[PROJ-123] Fix login form'and--amend --no-editkeep one prefix.--fixup=HEADgivesfixup! [PROJ-123] Fix login form.commit -Fand its amend, under a UTF-8 locale, give[PROJ-123] Änderung am Login.mainstays unchanged and shows no warning.🤖 Generated with Claude Code