Skip to content

Add protected main worktree branch for all projects#8

Merged
Kvadratni merged 8 commits intomainfrom
main-worktree
Feb 7, 2026
Merged

Add protected main worktree branch for all projects#8
Kvadratni merged 8 commits intomainfrom
main-worktree

Conversation

@Kvadratni
Copy link
Collaborator

@Kvadratni Kvadratni commented Feb 7, 2026

Summary

Introduces automatic tracking of the main repository worktree as a protected, non-deletable branch for every project. This ensures users always have a reference to their primary working directory and prevents accidental deletion of the main worktree.
image

Changes

  • Automatic main worktree registration: New projects now auto-create a branch entry for the main worktree during project creation, capturing the current branch and base branch
  • Backward compatibility for existing projects: Added migration logic that lazily creates main worktree branches for projects created before this feature, triggered when listing branches
  • Deletion protection: Main worktree branches are marked as non-deletable in the UI, with the delete option hidden from the context menu and deletion attempts blocked
  • Database schema evolution: Added is_main_worktree boolean column to the branches table with automatic migration for existing databases
  • New Git helper: Introduced get_current_branch() utility to reliably detect the active branch name, handling detached HEAD states gracefully

Architectural Decisions

  • Lazy migration approach: Rather than requiring a one-time migration script, the system automatically creates missing main worktree entries on-demand when branches are listed, ensuring zero-downtime upgrades
  • Repo path as worktree path: Main worktree branches use the repository path itself as the worktree path, distinguishing them from secondary worktrees created in separate directories

Kvadratni and others added 3 commits February 6, 2026 15:59
When a project is added to the branches view, the main worktree is now
automatically added as a branch. This allows users to switch branches
on the main worktree without creating a separate worktree.

Changes:
- Add is_main_worktree field to Branch struct and database schema
- Auto-create main worktree branch when creating a git project
- Add get_current_branch() function to detect the current branch
- Prevent deletion of main worktree branches in UI
- Update TypeScript types to include isMainWorktree field

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When a new project is added, the backend automatically creates a main
worktree branch entry. However, the UI wasn't reloading branches after
project creation, so the main worktree branch never appeared in the UI.

This fix makes handleNewProjectCreated async and calls loadData() after
adding the project to ensure the auto-created main worktree branch is
fetched and displayed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Projects created before the main worktree feature was added don't have
a main worktree branch entry in the database. This fix ensures that when
listing branches for a project, the main worktree branch is auto-created
if it doesn't exist.

This provides backward compatibility and ensures consistent behavior
across all projects, regardless of when they were created.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Kvadratni and others added 2 commits February 6, 2026 16:28
Add ability to delete projects from the settings modal without requiring the project to be empty. The delete button is now available in the project settings, making it easier to remove projects while preserving the main worktree branch and git repository.

Changes:
- Add "Delete Project" button to ProjectSettingsModal footer
- Add confirmation dialog for project deletion
- Wire up onDeleted callback to remove project from BranchHome list
- Clarify in dialog that main worktree and repository won't be deleted

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Make project deletion more discoverable by always showing the delete button in the project header, not just for empty projects. Users can now easily delete any project directly from the project view.

Changes:
- Remove isEmpty condition from delete button visibility
- Update button title from "Remove project" to "Delete project"
- Fix TypeScript type narrowing in onDeleted callback

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
baxen
baxen previously approved these changes Feb 7, 2026
Copy link
Collaborator

@baxen baxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works for me, but as a followup we need to figure out what we will do with the original working dir. i'm still tempted to enforce worktrees of some kind

… new worktree

Allow switching the checked-out branch on any worktree (including main)
via a clickable branch name in the card header. Rename "New Branch"
buttons to "New Worktree" throughout the UI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Kvadratni and others added 2 commits February 6, 2026 17:20
Pass onBranchUpdated callback from BranchHome to BranchCard so the
parent branches array updates when a branch switch occurs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove local-only filter so remote tracking branches are available.
For remote branches, strip the remote prefix (e.g. origin/) when
checking out so git creates a local tracking branch automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Kvadratni Kvadratni merged commit 7f01ba1 into main Feb 7, 2026
2 checks passed
@Kvadratni Kvadratni deleted the main-worktree branch February 7, 2026 01:29
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.

2 participants