Skip to content

harden(merge): custom branding-rebrand merge driver + .gitattributes to automate upstream-rebase brand sweep #77

Closed

Description

@thehoff

Problem

Every upstream rebase from `rtk-ai/rtk` re-introduces `rtk` strings via:

  • NEW upstream additions that touch our hardened branding lines (not conflicts — just additions; rerere doesn't help)
  • Refactors that move our brand-applied strings to a new file (rerere mismatches)

We catch most via `branding_lint` post-merge, but the current flow is:

  1. Merge upstream
  2. Run `cargo test`
  3. Branding lint fails
  4. Hand-fix each leak

That's 4-step manual labour every rebase. The 2026-05-15 heavy rebase (641 commits, v0.39 → v0.41) took a full day; even light rebases hit ≥1 lint failure each.

Goal

Make the rebrand SWEEP automatic for the high-leak file set, and document the new flow in UPSTREAM_REBASE.md.

Proposed approach

1. Centralise the substitution rules

A single `branding/rebrand.toml` listing:
```toml
[substitutions]
"RTK savings" = "ContextCrawler savings"
"RTK adoption" = "ContextCrawler adoption"
"[rtk]" = "[contextcrawler]"
"$(rtk " = "$(contextcrawler "

... pulled from FORBIDDEN_TOKENS history

```

Substitutions are SCOPED (only fire on lines added or modified by the merge; only inside specific path globs) to avoid mangling legitimate references.

2. Custom merge driver

`.gitattributes`:
```
src/main.rs merge=branding-rebrand
src/cmds//*.rs merge=branding-rebrand
src/discover/report.rs merge=branding-rebrand
src/analytics/
/*.rs merge=branding-rebrand
src/hooks/init.rs merge=branding-rebrand
```

`.git/config` driver:
```
[merge "branding-rebrand"]
name = Three-way merge then apply branding substitutions
driver = scripts/branding-merge-driver.sh %O %A %B %L %P
```

Driver script:

  1. Run `git merge-file %A %O %B` (standard 3-way)
  2. Apply substitutions from `branding/rebrand.toml` to %A — diff-aware, NEW lines only
  3. Exit 0 / 1 based on merge-file result

3. CI gate retained as backstop

`branding_lint` still runs in CI — if a substitution rule is missing or wrong, CI still blocks the merge.

4. UPSTREAM_REBASE.md updates

Add the new flow + a "if branding-rebrand driver misfires, here's how to debug" section.

Definition of done

  • `.gitattributes` registered for the high-leak file set
  • `branding/rebrand.toml` populated from FORBIDDEN_TOKENS + survey of past leak commits
  • `scripts/branding-merge-driver.sh` shipped with unit tests on the substitution engine
  • `scripts/install-merge-driver.sh` one-shot to register the driver in `.git/config` (for fresh clones)
  • UPSTREAM_REBASE.md updated
  • Dry-run on commit c35339e (last heavy upstream merge) reproduces the hand-fix sweep without manual intervention

Risks

  • Driver corrupts legitimate code: mitigation = scoped substitutions + diff-aware (NEW lines only) + branding_lint as backstop
  • Substitution rules drift from FORBIDDEN_TOKENS: mitigation = generate the TOML from the test file as part of `cargo test`, or vice versa — single source of truth

Why

Durably fixes the whack-a-mole. After this lands, an upstream rebase that touches a branding-leak file produces a CLEAN tree without manual intervention — only NEW leak CLASSES should fail (not new instances of known classes).

Review plan

Multi-model peer review (claude + codex + gemini) on the merge-driver design BEFORE implementation, since driver bugs cause silent code corruption.

Sequencing

  • Issue A (clap-aware lint) and Issue B (KNOWN_UNBRANDED debt reduction) ship first.
  • Their outputs feed the substitution rule set used here.
  • This issue lands LAST in the trilogy.

Activity

  1. added a commit that references this issue on Jun 4, 2026
  2. thehoff commented on Jun 10, 2026

    @thehoff
    OwnerAuthor

    Closing — not pursuing a custom rebrand merge driver (design PR #80 closed too). Upstream rebases use the existing sentinel-block convention.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions