Skip to content

Add --first-parent-baseline flag - #1450

Open
brady-zip wants to merge 1 commit into
chromaui:mainfrom
brady-zip:first-parent-baseline
Open

Add --first-parent-baseline flag#1450
brady-zip wants to merge 1 commit into
chromaui:mainfrom
brady-zip:first-parent-baseline

Conversation

@brady-zip

Copy link
Copy Markdown

Adds an opt-in --first-parent-baseline [branch] flag that passes --first-parent to the git rev-list ancestry walk in nextCommits, so baseline resolution stays on the mainline instead of descending into merged-in branch histories.

Context and motivation: #1449. This is the smaller of the two flags proposed there, and it carries the plumbing that the second one (--ignore-merged-pr-builds) builds on, so it goes first.

Behaviour

Default (flag unset) behaviour is byte-identical to today — the flag only ever adds --first-parent to the rev-list invocation.

Branch-glob scoped, following --ignore-last-build-on-branch exactly, so it can be enabled on the trunk only while PR builds keep the default base-branch baseline:

# .github/workflows/…
with:
  firstParentBaseline: master
// chromatic.config.json
{ "firstParentBaseline": "master" }

--first-parent-baseline with no value means true (via trueIfSet), matching --auto-accept-changes and friends.

Implementation

Standard option plumbing, one change per file:

File Change
node-src/lib/parseArguments.ts Help text under Chromatic options (alphabetical) and flags entry
node-src/types.ts Flags.firstParentBaseline, Options.firstParentBaseline
node-src/lib/getOptions.ts defaultOptions entry + trueIfSet(flags.firstParentBaseline)
node-src/lib/getConfiguration.ts Zod z.union([z.string(), z.boolean()])
action.yml firstParentBaseline input (alphabetical)
action-src/main.ts getInput + runNode flags entry
node-src/tasks/gitInfo.ts GitInfoInput + extractGitInfoInput, resolved via git.matchesBranch(firstParentBaseline || false)
node-src/git/getParentCommits.ts Boolean threaded getParentCommitsstepnextCommits, interpolated into the rev-list command

The glob is resolved in the gitInfo task and getParentCommits receives a plain boolean, so node-src/git/ stays glob-unaware — same seam ignoreLastBuildOnBranch uses.

Testing

  • node-src/git/getParentCommits.test.ts: new firstParentBaseline case on the simpleLoop fixture (F = merge(D, E), D is F's first parent) asserting both halves in one test — without the option E is included (it is a genuine ancestor), with the option the walk never reaches it. Because this suite runs getParentCommits against real generated git repositories, the assertion only holds if --first-parent actually reaches git rev-list.
  • node-src/lib/getOptions.test.ts: flag → option for the glob form, and the bare-flag trueIfSet path; plus firstParentBaseline: undefined added to the defaults assertion.
  • yarn typescript:check, yarn lint, yarn build, yarn test all clean locally (1007 passing).

Labels

Requesting minor + release — I don't have permission to set them.

Resolve the TurboSnap baseline by walking only the first-parent (mainline)
history, so ancestry never descends into merged-in branch histories.

Plumbed as a branch-glob option following `ignoreLastBuildOnBranch`: the glob is
matched in the `gitInfo` task and `getParentCommits` receives a plain boolean, so
`node-src/git/` stays glob-unaware. The boolean is threaded through `step` into
`nextCommits`, where it interpolates `--first-parent` into the `git rev-list`
ancestry walk.

Default (flag unset) behavior is unchanged.
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