fix(worktree): seed empty initial commit on unborn HEAD before worktree setup - #675
Open
tarikcosovic97 wants to merge 1 commit into
Open
Conversation
…ee setup Fresh `git init` + `dotbot init` + workflow run used to produce a scary `Cannot find base branch` warning on every Git version, and on Git <2.42 also crashed the first `git worktree add` with `fatal: invalid reference` (because `worktree add --orphan` didn't exist yet, and the fallback tried to attach to a branch that wasn't there). Solve both symptoms without a Git version floor — Ubuntu 22.04 LTS ships Git 2.34.1 through May 2027, so raising the floor as tried in the earlier attempt (andresharpe#664) locks that platform out. - Add `Initialize-UnbornRepositoryForWorktree` in Dotbot.Worktree: creates an empty commit with `dotbot@localhost` identity overrides on unborn HEAD, idempotent, uses the branch git already selected via `init.defaultBranch`. Called from `Initialize-DotbotTaskWorktreeForProcess` right before `Assert-OnBaseBranch`, so downstream base-branch resolution and `git worktree add -b <task> <path> <base>` just work on any Git. - `Assert-OnBaseBranch` now returns `$null` early on unborn HEAD as defense-in-depth for callers that reach it directly. In the normal flow the seed above means it never sees an unborn repo. Closes andresharpe#659 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced Aug 4, 2026
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.
Linked issue
Closes #659
Summary of changes
Starting any workflow in a brand-new project (
git init+dotbot init+ workflow run) used to surface a scary⚠ Branch guard warning: Cannot find base branchline on every Git version — and on Git <2.42 also crashed the first worktree add with a crypticfatal: invalid reference: task/…(becausegit worktree add --orphandidn't exist yet and the fallback tried to attach to a branch that wasn't there).The earlier attempt at #664 raised the operating floor to Git 2.42. That's incompatible with Ubuntu 22.04 LTS (Git 2.34.1, supported through May 2027), which is why the reviewer closed it. This PR takes the ticket's originally-preferred path instead: seed the repo with an empty initial commit at worktree-setup time so downstream code has a real branch to attach to, on any Git version.
Initialize-UnbornRepositoryForWorktreeinDotbot.Worktree. Runsgit commit --allow-empty -m "chore: initial commit"withdotbot@localhostidentity overrides so it works on machines whereuser.name/user.emailhave never been configured. Reuses whatever branch git already selected viainit.defaultBranch— no naming policy imposed. Idempotent: returnscreated=falsewhen the repo already has commits.Initialize-DotbotTaskWorktreeForProcess(Invoke-WorkflowProcess.ps1) directly beforeAssert-OnBaseBranch, so the base-branch resolution, integration-branch creation, andgit worktree add -b <task> <path> <base>calls that follow have a real HEAD to reference. The old--orphancode paths become cold code — kept as-is for defense-in-depth.Assert-OnBaseBranchreturns$nullearly on unborn HEAD as defense-in-depth for any caller that bypasses the seed. In the normal flow the seed above means it never sees an unborn repo, but this removes the misleadingCannot find base branchwarning from every direct-call site too.Together these turn the "no commits yet" first-run flow from noisy-and-broken (old Git) or noisy-but-works (new Git) into quiet and correct on any Git ≥2.20 or so — comfortably including the Ubuntu 22.04 default.
Screenshots / recordings
N/A — CLI-only behaviour change.
Testing notes
New assertions land in
tests/Test-Worktree.ps1under a new "Unborn HEAD — auto initial commit + silent Assert" section:Initialize-UnbornRepositoryForWorktree—created=trueon unborn HEAD; reports branch name; HEAD is now valid; commit message ischore: initial commit; one commit exists; second call is idempotent (created=false, no extra commit).Assert-OnBaseBranch— does not throw on unborn HEAD; returns$null; does not create a commit.Results:
tests/Test-Worktree.ps1— 87/87 pass (10 new assertions)tests/Test-WorkflowManifest.ps1— 538/538 pass (no regression)tests/Test-Runtime.ps1— 124/124 pass (1 skip, unrelated)Manual verification on Git 2.53:
Initialize-UnbornRepositoryForWorktreeseeds a single commit on a freshgit initrepo with no configured git identity; subsequent worktree operations proceed without the branch-guard warning.No prerequisite bump this time — README is unchanged; the fix works on Ubuntu 22.04's default Git 2.34.1.
Checklist