Skip to content

fix(workspace): render the branch guard from the workflow model both ways - #1643

Merged
c-vigo merged 2 commits into
devfrom
bugfix/1642-bidirectional-branch-guard
Sep 17, 2026
Merged

c-vigo merged 2 commits into
devfrom
bugfix/1642-bidirectional-branch-guard

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Description

render_workflow_model applies the gitflow → trunk retarget one way — it
early-returns unless the resolved model is trunk. For every managed file it
touches that is harmless: the template overwrite restores the gitflow shape on the
next upgrade and the render simply does not re-run. .pre-commit-config.yaml is
preserved, so the trunk edits stayed in it forever.

A consumer switching back to gitflow therefore lost the dev-branch guard silently:
no-commit-to-branch stopped blocking direct commits to dev, on a repo whose
.vig-os says gitflow. No error, no notice.

Last instance of the class fixed in #1640.

Type of Change

  • fix -- Bug fix

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

I scoped this out of #1641 believing it spanned many files and needed its own
design. That premise was wrong, and measuring it first is what made the fix small:
every other target self-heals, so the entire stale surface is two lines of one file.

Target Managed / preserved After a trunk → gitflow round-trip
ci.yml, codeql.yml, sync-issues.yml, prepare-release.yml, promote-release.yml managed restored
.github/renovate-default.json managed restored (["dev"])
.devcontainer/justfile.gh managed restored
.claude/skills/branch-naming/SKILL.md managed restored
.pre-commit-config.yaml preserved STALE

So the .pre-commit-config.yaml edits move out of render_workflow_model into a
new render_branch_guard_model, which runs for both models and renders the dev
clause from the resolved model instead of only subtracting it under trunk. It
goes through the precommit_render_target resolver added in #1640, keeping the
symlink and absent-file refusals in one place. Each direction's anchors stop
matching once applied, so a re-run is a no-op and a default gitflow scaffold stays
byte-identical to the template.

One trap worth recording, because it silently produced a no-op fix. GNU sed
4.10 treats a mid-pattern $ in a basic regular expression as an end anchor, not
a literal. So the obvious insert pattern

s|(?!main$)(?!^(chore)|(?!main$)(?!dev$)(?!^(chore)|

matches nothing at all — and fails silently, leaving the file untouched. The
existing (?!dev$) strip only works because its $) sits at the very end of the
pattern. Both metacharacters are escaped in the insert pattern for that reason;
the replacement side needs no escaping, since sed gives $/^ no meaning there.
The comment in the source records this so the next person does not rediscover it.

Flake-hooks consumers were never affected: their guard comes from mkProjectShell,
which reads DEVKIT_WORKFLOW at eval time (#1224/#1434) and was already correct in
both directions. It was only the scaffolded YAML that was one-way.

Changelog Entry

### Fixed

- **Switching `trunk` back to `gitflow` restores the dev-branch guard**
  ([#1642](https://github.com/vig-os/devkit/issues/1642))
  - `render_workflow_model` applied the `gitflow -> trunk` retarget one way. For
    every managed file it touches that is harmless — the template overwrite
    restores the gitflow shape on the next upgrade — but `.pre-commit-config.yaml`
    is preserved, so a consumer switching back kept the trunk edits and lost the
    `(?!dev$)` clause: `no-commit-to-branch` silently stopped blocking direct
    commits to `dev` on a repo whose manifest said `gitflow`
  - The dev clause now renders from the resolved model in BOTH directions, in a
    new `render_branch_guard_model` that runs for either model and goes through
    the `precommit_render_target` resolver. Each direction's anchors stop
    matching once applied, so a re-run is a no-op and a default gitflow scaffold
    stays byte-identical to the template
  - Flake-hooks consumers were never affected: their guard comes from
    `mkProjectShell`, which reads `DEVKIT_WORKFLOW` at eval time and was already
    correct in both directions

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

Four new bats cases, committed first (5c33a7ca) with the two behavioural ones
red:

  • trunk → gitflow restores both the (?!dev$) clause and its comment (red)
  • the restored file matches the template byte for byte, the way a managed file
    does — this is the assertion that caught the silent no-op sed (red)
  • the gitflow render is idempotent: a second upgrade does not double-insert
    (green before, pins the new code path)
  • the render refuses a symlinked config (green before via [BUG] Clearing a scaffold knob leaves the previous render in the preserved .pre-commit-config.yaml #1640's resolver; pins
    that the refactor keeps it)

Full runs, all green:

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

The contradiction guard still refuses a --workflow flag that contradicts the
persisted DEVKIT_WORKFLOW; this changes nothing there. The switch path this fixes
is the guard's own documented step 3 — set DEVKIT_WORKFLOW in .vig-os on a
dedicated branch and re-run the upgrade.

Refs: #1642

@c-vigo
c-vigo enabled auto-merge September 17, 2026 08:01
@c-vigo
c-vigo merged commit 0b32ebd into dev Sep 17, 2026
12 checks passed
@c-vigo
c-vigo deleted the bugfix/1642-bidirectional-branch-guard branch September 17, 2026 08:10
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.

1 participant