Repository navigation
fix(core): keep the recorded project name inside a git worktree - #60
Merged
Merged
Conversation
The project name came from the directory name. In a linked worktree (`git worktree add ../my-app-feature`) the first command treated the new directory as a rename: it restamped `projectName` in the committed manifest, pushed the real name into `previousNames`, and fed the worktree directory name into everything derived from ctx.projectName, including the package.json name, the compose `name:`, the AGENTS.md title and the port hashes. Runtime checks then looked for containers under a compose project that the committed docker-compose.yml did not use, and `cleanup` in the worktree could offer to remove the main checkout's containers as "detached" leftovers. resolveProjectName returns the manifest's recorded name inside a linked worktree and the directory name everywhere else. writeManifest, buildRunContext, reconcileProjectName and the CLI's own context builders (add/remove, upgrade, describe, cleanup) all go through it, so a rename of the main checkout is still detected. A worktree is told apart by a `commondir` file in the directory its `.git` file points to. Checking for a `.git` file alone would also match submodules.
nielsvanrijn-sevenlab
approved these changes
Oct 5, 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.
What this changes
Inside a linked git worktree, battlestack now uses the project name recorded in
.battlestack/manifest.jsoninstead of the worktree's directory name. A rename of the main checkout is still detected and restamped as before.Why
The project name came from
path.basename(projectDir). Running any command ingit worktree add ../my-app-featurewas treated as a directory rename:projectNamewas overwritten and the real name moved intopreviousNamespull,addandupgraderegenerated committed files with the worktree name: thepackage.jsonname, the composename:, theAGENTS.md/README.mdtitles and the PWA manifestdescribe, port diagnosis, compose detection) looked for containers under the worktree name whiledocker-compose.ymlstill said the real one, which caused duplicate containers and errorscleanupin a worktree could list the main checkout's live containers and volumes as leftovers from a "previous name"Type of change
AI assistance
Agent, service and model, if you know it: Claude Code, Opus 5.5
How much of this is agent-written?
Feature versions
Testing
packages/core/test/project-name.test.tscreates a real repo plusgit worktree addin a tmp dir and checks:resolveProjectNameand frombuildRunContextreconcileProjectNamenorwriteManifestchangesprojectNameorpreviousNamesthere.gitfile is not mistaken for a worktreeWith the fix removed, the three worktree tests fail. The rename and detection tests keep passing.
pnpm tscpassespnpm testpassesChecklist
docs/troubleshooting.md)Anything else
name:already committed indocker-compose.yml. Fully isolated per-worktree stacks would be a separate feature..battlestack/manifest.jsonfrom main (or fixprojectNameandpreviousNamesby hand) before runningbattlestack pull.