|
| 1 | +--- |
| 2 | +status: shipped |
| 3 | +date: 2026-06-16 |
| 4 | +slug: branch-prefix-patch-on-non-merge |
| 5 | +supersedes: null |
| 6 | +superseded_by: null |
| 7 | +pr: 24 |
| 8 | +outcome: Shipped. Opt-in patch_on_non_merge_commit flag (default False) added to |
| 9 | + branch-prefix; a non-merge HEAD commit bumps patch when enabled. Conclusions |
| 10 | + promoted into architecture/strategies.md. |
| 11 | +--- |
| 12 | + |
| 13 | +# Design: Opt-in patch bump for non-merge commits (branch-prefix) |
| 14 | + |
| 15 | +## Summary |
| 16 | + |
| 17 | +Add an opt-in `branch-prefix` config flag, `patch_on_non_merge_commit` (default |
| 18 | +`False`), that makes the strategy return `Bump.PATCH` instead of `Bump.NONE` |
| 19 | +when the HEAD commit on the default branch is a plain (non-merge) commit. Teams |
| 20 | +that allow direct pushes to the default branch can then auto-tag a patch release |
| 21 | +for each such push instead of silently skipping. Default-off preserves today's |
| 22 | +behavior byte-for-byte. Scope: the `branch-prefix` strategy only, the |
| 23 | +non-merge exit only. |
| 24 | + |
| 25 | +## Motivation |
| 26 | + |
| 27 | +`branch-prefix` exists to bump on merge commits: the merged branch name carries |
| 28 | +the level (`feature/` → minor, `bugfix/`/`hotfix/` → patch). A commit pushed |
| 29 | +directly to the default branch — not via an MR/PR — carries no merge mark, so |
| 30 | +`BranchPrefixStrategy.decide` returns `Bump.NONE` and the run ends with status |
| 31 | +`no_merge_commit` (`semvertag/strategies/branch_prefix.py:33-34`, |
| 32 | +`semvertag/_use_case.py:52`). For a team that permits direct pushes, that means |
| 33 | +real changes land on the default branch with no version movement at all. A |
| 34 | +sensible default for "code changed but no merge told me how much" is the |
| 35 | +smallest bump: patch. Making it opt-in lets those teams get an automatic patch |
| 36 | +release per direct push without affecting anyone relying on merge-only bumping. |
| 37 | + |
| 38 | +## Non-goals |
| 39 | + |
| 40 | +- Not changing the default behavior: the flag defaults to `False`, so existing |
| 41 | + users see no change. |
| 42 | +- Not touching the `conventional-commits` strategy; a non-conforming commit |
| 43 | + there still returns `Bump.NONE`. An analogous fallback can be a later change. |
| 44 | +- Not changing the merge-with-unrecognized-prefix exit |
| 45 | + (`branch_prefix.py:39`): a commit that *is* a merge but matches neither the |
| 46 | + minor nor patch tables still returns `Bump.NONE`. The flag only governs the |
| 47 | + "not a merge at all" case, matching the request's framing. |
| 48 | +- No CLI flag: the existing `branch_prefix` config fields (`minor`, `patch`, |
| 49 | + `merge_mark_texts`) are env/config-only; the new field follows suit. |
| 50 | +- No use-case or output-messaging change (see Design §3). |
| 51 | + |
| 52 | +## Design |
| 53 | + |
| 54 | +### 1. Config field |
| 55 | + |
| 56 | +Add one field to `BranchPrefixConfig` |
| 57 | +(`semvertag/strategies/branch_prefix.py`): |
| 58 | + |
| 59 | +```python |
| 60 | +class BranchPrefixConfig(pydantic.BaseModel): |
| 61 | + model_config = pydantic.ConfigDict(frozen=True) |
| 62 | + |
| 63 | + minor: tuple[_NonEmptyStr, ...] = pydantic.Field(default=("feature/",), min_length=1) |
| 64 | + patch: tuple[_NonEmptyStr, ...] = pydantic.Field(default=("bugfix/", "hotfix/"), min_length=1) |
| 65 | + merge_mark_texts: tuple[_NonEmptyStr, ...] = pydantic.Field( |
| 66 | + default=("Merge branch", "Merge pull request"), |
| 67 | + min_length=1, |
| 68 | + ) |
| 69 | + patch_on_non_merge_commit: bool = False |
| 70 | +``` |
| 71 | + |
| 72 | +It rides the existing `Settings.branch_prefix: BranchPrefixConfig` wiring |
| 73 | +(`semvertag/_settings.py:98`) and the IoC builder |
| 74 | +(`semvertag/ioc.py:68-69`), so it is settable via |
| 75 | +`SEMVERTAG_BRANCH_PREFIX__PATCH_ON_NON_MERGE_COMMIT=true` with no new plumbing. |
| 76 | +Standard pydantic-settings bool coercion applies (`true`/`1`/`yes` → `True`). |
| 77 | + |
| 78 | +### 2. `decide` change |
| 79 | + |
| 80 | +The non-merge exit gains a single ternary; nothing else in the method moves: |
| 81 | + |
| 82 | +```python |
| 83 | +def decide(self, commit: Commit) -> Bump: |
| 84 | + subject: typing.Final = subject_line(commit.message) |
| 85 | + if not any(mark in subject for mark in self.config.merge_mark_texts): |
| 86 | + return Bump.PATCH if self.config.patch_on_non_merge_commit else Bump.NONE |
| 87 | + if any(prefix in subject for prefix in self.config.minor): |
| 88 | + return Bump.MINOR |
| 89 | + if any(prefix in subject for prefix in self.config.patch): |
| 90 | + return Bump.PATCH |
| 91 | + return Bump.NONE |
| 92 | +``` |
| 93 | + |
| 94 | +### 3. Why no use-case or messaging change |
| 95 | + |
| 96 | +`semvertag/_use_case.py:51-60` turns any non-`NONE` bump into a real tag and |
| 97 | +only emits the strategy's `no_bump_status` / `no_bump_reason` on the `NONE` |
| 98 | +path. When the flag fires, a non-merge commit yields `Bump.PATCH`, so the run |
| 99 | +produces a normal `tagged` (or `dry_run`) result through the existing path. The |
| 100 | +`no_merge_commit` status/reason ClassVars are still correct: they are read only |
| 101 | +when `decide` returns `NONE`, which still happens for unrecognized merges and |
| 102 | +for non-merge commits when the flag is off. No new status string is introduced. |
| 103 | + |
| 104 | +## Testing |
| 105 | + |
| 106 | +Unit tests in `tests/unit/test_branch_prefix_strategy.py`. The global pytest |
| 107 | +config runs `--cov-branch` with `fail_under = 100`, so the new ternary's `True` |
| 108 | +and `False` arms must both be exercised. |
| 109 | + |
| 110 | +- **Flag on, non-merge → PATCH.** A `BranchPrefixStrategy` built with |
| 111 | + `BranchPrefixConfig(patch_on_non_merge_commit=True)` returns `Bump.PATCH` for |
| 112 | + each existing `_NON_MERGE_CASES` subject (`feat: ...`, `docs: ...`, `""`, |
| 113 | + lowercase `merge branch ...`). |
| 114 | +- **Flag on does not disturb the merge paths.** With the flag on, a recognized |
| 115 | + feature merge still returns `MINOR`, a bugfix/hotfix merge still `PATCH`, and |
| 116 | + an unrecognized *merge* (`_UNRECOGNIZED_MERGE_CASES`) still `NONE` — proving |
| 117 | + the flag governs only the non-merge exit, not line 39. |
| 118 | +- **Flag off (default) unchanged.** The existing |
| 119 | + `test_returns_none_when_message_is_not_a_merge_commit` already covers the |
| 120 | + `False` arm; it stays green untouched. |
| 121 | +- **Default value.** Assert `BranchPrefixConfig().patch_on_non_merge_commit is |
| 122 | + False`. |
| 123 | + |
| 124 | +No config-validation case is needed (a bool cannot be empty). No |
| 125 | +integration-level test is required: the `decide → PATCH → tag` wiring is already |
| 126 | +covered by existing use-case tests that exercise a non-`NONE` bump. |
| 127 | + |
| 128 | +## Docs |
| 129 | + |
| 130 | +On merge (per the planning convention, the change promotes its conclusions into |
| 131 | +the affected capability doc): |
| 132 | + |
| 133 | +- `architecture/strategies.md` — note the opt-in `patch_on_non_merge_commit` |
| 134 | + under the `branch-prefix` section's step 1. |
| 135 | +- mkdocs config/reference page for `branch-prefix` — document the new env var |
| 136 | + and its default. |
| 137 | + |
| 138 | +## Risk |
| 139 | + |
| 140 | +Low. The behavior change is gated behind a default-`False` flag, so existing |
| 141 | +installs are unaffected. The single new branch is fully covered by the |
| 142 | +100%-branch gate. The main user-facing consideration is conceptual, not a code |
| 143 | +risk: with the flag on, *any* direct push to the default branch (including a |
| 144 | +docs typo fix) triggers a patch tag — which is exactly the intended semantics, |
| 145 | +and is documented as such. No rollback concern: flipping the flag back to |
| 146 | +`False` restores prior behavior immediately. |
0 commit comments