Skip to content

feat: add git-worktree-flow-adopt and git-worktree-flow-eject commands#73

Merged
avihut merged 6 commits intodevelopfrom
daft-68/adopt-eject
Jan 24, 2026
Merged

feat: add git-worktree-flow-adopt and git-worktree-flow-eject commands#73
avihut merged 6 commits intodevelopfrom
daft-68/adopt-eject

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Jan 24, 2026

Summary

  • Add git-worktree-flow-adopt command to convert traditional repos to worktree layout
  • Add git-worktree-flow-eject command to convert worktree layout back to traditional
  • Add shell wrappers for automatic cd after adopt/eject
  • Properly handle bare repo index cleanup and worktree index initialization

Changes

New Commands

  • git-worktree-flow-adopt: Converts a traditional Git repository to daft's worktree-based layout
  • git-worktree-flow-eject: Converts a worktree-based repository back to traditional layout

Features

  • Preserves uncommitted changes during conversion
  • Supports --dry-run mode
  • Supports --branch option for eject to choose which branch to keep
  • Supports --force option for eject to remove dirty worktrees
  • Runs appropriate hooks (post-clone for adopt, pre/post-remove for eject)
  • Shell wrapper integration for automatic cd to new worktree/project root

Bug Fixes

  • Remove bare repo index file after adopt (prevents stale git status)
  • Initialize worktree index after adopt (prevents "all files deleted" status)
  • Add cd_path output to both commands for shell wrapper integration

Test plan

  • just test-integration-flow-adopt passes (7 tests)
  • just test-integration-flow-eject passes (8 tests)
  • cargo clippy -- -D warnings passes
  • Manual testing with real repository confirms:
    • Clean git status after adopt
    • Shell cd works after adopt (with shell wrapper)
    • Shell cd works after eject (with shell wrapper)

🤖 Generated with Claude Code

avihut and others added 6 commits January 24, 2026 08:36
Add two commands for converting repositories between traditional and
worktree-style layouts:

- git-worktree-flow-adopt: Convert traditional repo to worktree layout
  - Preserves uncommitted changes
  - Supports --dry-run, --quiet, --verbose, --trust-hooks, --no-hooks
  - Comprehensive man page with workflow documentation

- git-worktree-flow-eject: Convert worktree layout back to traditional
  - Supports -b/--branch to specify which branch to keep
  - Supports --force to delete dirty worktrees
  - Handles uncommitted changes appropriately

These are explicit, infrequently-used commands without shortcuts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove bare repo index file after adopt (bare repos don't need one)
- Initialize worktree index with git reset after adopt
- Add cd_path output to eject command for shell wrapper
- Add flow-adopt and flow-eject to shell wrappers (bash/zsh/fish)
- Add tests for clean git status after adopt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use a staging directory inside .git/ to safely move project files during
adopt. This fixes the case where the branch name (e.g., "test") matches
an existing directory in the project - previously this would fail with
"Invalid argument" when trying to move a directory into its own subdirectory.

The fix moves files in two steps:
1. Move all files to .git/daft-adopt-staging/
2. Create the worktree directory and move files from staging

Also fixes missing `remote` field in init.rs tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When running eject without --branch and the default branch (master/main)
doesn't have a worktree, the command now falls back to the first
available worktree instead of failing with an error.

This fixes the case where a user only has a non-default branch worktree
(e.g., "test") and runs eject - it now correctly uses that branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use a staging directory inside .git/ to safely move files during eject.
This fixes the case where the branch name (e.g., "test") matches a
directory inside the worktree - previously this would fail when trying
to move test/test to test while the worktree directory still exists.

The fix moves files in three steps:
1. Move files from worktree to .git/daft-eject-staging/
2. Remove the worktree directory
3. Move files from staging to project root

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add symlinks and tests for the new git-worktree-flow-adopt and
git-worktree-flow-eject commands to the CI workflow.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@avihut avihut linked an issue Jan 24, 2026 that may be closed by this pull request
13 tasks
@avihut avihut added this to the v1.0.0 milestone Jan 24, 2026
@avihut avihut added the enhancement New feature or request label Jan 24, 2026
@avihut avihut self-assigned this Jan 24, 2026
@avihut avihut merged commit c23fdae into develop Jan 24, 2026
4 checks passed
@avihut avihut deleted the daft-68/adopt-eject branch January 24, 2026 08:45
avihut added a commit that referenced this pull request Jan 24, 2026
#73)

* feat: add git-worktree-flow-adopt and git-worktree-flow-eject commands

Add two commands for converting repositories between traditional and
worktree-style layouts:

- git-worktree-flow-adopt: Convert traditional repo to worktree layout
  - Preserves uncommitted changes
  - Supports --dry-run, --quiet, --verbose, --trust-hooks, --no-hooks
  - Comprehensive man page with workflow documentation

- git-worktree-flow-eject: Convert worktree layout back to traditional
  - Supports -b/--branch to specify which branch to keep
  - Supports --force to delete dirty worktrees
  - Handles uncommitted changes appropriately

These are explicit, infrequently-used commands without shortcuts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: resolve adopt/eject post-conversion issues

- Remove bare repo index file after adopt (bare repos don't need one)
- Initialize worktree index with git reset after adopt
- Add cd_path output to eject command for shell wrapper
- Add flow-adopt and flow-eject to shell wrappers (bash/zsh/fish)
- Add tests for clean git status after adopt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: handle adopt when branch name matches existing directory

Use a staging directory inside .git/ to safely move project files during
adopt. This fixes the case where the branch name (e.g., "test") matches
an existing directory in the project - previously this would fail with
"Invalid argument" when trying to move a directory into its own subdirectory.

The fix moves files in two steps:
1. Move all files to .git/daft-adopt-staging/
2. Create the worktree directory and move files from staging

Also fixes missing `remote` field in init.rs tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: eject falls back to available worktree when default branch missing

When running eject without --branch and the default branch (master/main)
doesn't have a worktree, the command now falls back to the first
available worktree instead of failing with an error.

This fixes the case where a user only has a non-default branch worktree
(e.g., "test") and runs eject - it now correctly uses that branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: handle eject when branch name matches directory in worktree

Use a staging directory inside .git/ to safely move files during eject.
This fixes the case where the branch name (e.g., "test") matches a
directory inside the worktree - previously this would fail when trying
to move test/test to test while the worktree directory still exists.

The fix moves files in three steps:
1. Move files from worktree to .git/daft-eject-staging/
2. Remove the worktree directory
3. Move files from staging to project root

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* ci: add flow-adopt and flow-eject to CI workflow

Add symlinks and tests for the new git-worktree-flow-adopt and
git-worktree-flow-eject commands to the CI workflow.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add git-worktree-adopt and git-worktree-eject commands for repo layout conversion

1 participant