-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add git-wt worktree management to developer plugin #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
devin-ai-integration
wants to merge
5
commits into
main
Choose a base branch
from
devin/1772202475-add-git-wt-to-developer-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
93cb8e8
feat: add git-wt worktree management to developer plugin
devin-ai-integration[bot] 55e3770
feat: add VERSION file and LICENSE attribution for bundled git-wt
devin-ai-integration[bot] ca5ba79
refactor: fetch git-wt from upstream instead of bundling it
devin-ai-integration[bot] a983971
fix: update README wording from bundled to fetched
devin-ai-integration[bot] f009076
fix: address Copilot review feedback
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| name: worktree | ||
| description: Manage git worktrees using git-wt. Usage - /worktree add <branch> [source], /worktree rm [branch], /worktree ls, /worktree help | ||
| allowed-tools: Bash, Read, Write | ||
| --- | ||
|
|
||
| # Git Worktree Management | ||
|
|
||
| Manage git worktrees using the [git-wt](https://github.com/vojtabiberle/git-wt) script, fetched from upstream. | ||
|
|
||
| ## Instructions | ||
|
|
||
| 1. Validate we are inside a git repository: | ||
| ```bash | ||
| git rev-parse --is-inside-work-tree | ||
| ``` | ||
|
|
||
| 2. Fetch or update the git-wt script directly from upstream: | ||
| ```bash | ||
| GIT_WT_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/git-wt" | ||
| if [[ -d "$GIT_WT_DIR/.git" ]]; then | ||
| git -C "$GIT_WT_DIR" fetch --quiet 2>/dev/null || true | ||
| else | ||
| git clone --quiet https://github.com/vojtabiberle/git-wt.git "$GIT_WT_DIR" | ||
| fi | ||
| GIT_WT="$GIT_WT_DIR/git-wt" | ||
| ``` | ||
|
|
||
| 3. Parse the user's arguments from `$ARGUMENTS`. Only accept known subcommands: | ||
| - `add <branch> [source]` — create a worktree | ||
| - `rm [branch]` — remove a worktree | ||
| - `ls` — list worktrees | ||
| - `help` — show help | ||
|
|
||
| 4. Run the git-wt script with `--non-interactive` flag, validating and safely passing arguments: | ||
| ```bash | ||
| # Parse arguments into positional parameters | ||
| set -- $ARGUMENTS | ||
| subcommand="$1" | ||
| shift || true | ||
|
|
||
| case "$subcommand" in | ||
| add|rm|ls|help) | ||
| "$GIT_WT" --non-interactive "$subcommand" "$@" | ||
| ;; | ||
| *) | ||
| echo "Error: unknown subcommand: $subcommand" >&2 | ||
| echo "Usage: /worktree <add|rm|ls|help> [args...]" >&2 | ||
| ;; | ||
| esac | ||
| ``` | ||
|
|
||
| 5. Report the result to the user. For `add`, highlight the worktree path (last line of output). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| --- | ||
| name: git-worktree | ||
| description: Manage git worktrees using the git-wt helper script. Use when user asks to create, list, remove, or navigate worktrees, work in parallel on multiple branches, or set up isolated development environments. Triggers on phrases like "create worktree", "new worktree", "worktree for branch", "/worktree", "wt add", "wt rm", "wt ls". | ||
| --- | ||
|
|
||
| # Git Worktree Management (git-wt) | ||
|
|
||
| Manage git worktrees using the [git-wt](https://github.com/vojtabiberle/git-wt) helper script, fetched from upstream on each use. | ||
|
|
||
| ## Working Directory Context | ||
|
|
||
| **CRITICAL: All commands MUST be run from the user's project root directory, NOT from the skill directory.** | ||
|
|
||
| - The user will be in THEIR project directory when invoking this skill | ||
| - The setup script clones/pulls git-wt to `~/.local/share/git-wt` and prints the executable path | ||
| - **DO NOT `cd` into the skill directory** | ||
|
|
||
| `SKILL_DIR` = directory containing this SKILL.md (automatically resolved by Claude) | ||
|
|
||
| ## Setup | ||
|
|
||
| Before using git-wt, fetch or update it: | ||
|
|
||
| ```bash | ||
| GIT_WT="$("$SKILL_DIR/scripts/ensure-git-wt.sh")" | ||
| ``` | ||
|
|
||
| This clones `vojtabiberle/git-wt` to `~/.local/share/git-wt` (pinned to a known-good commit) or updates the existing clone. The script prints the path to the `git-wt` executable on stdout. If the network is unavailable, it falls back to the existing local version. | ||
|
|
||
| All subsequent commands use `$GIT_WT`. Pass `--non-interactive` to suppress prompts for commands that may prompt (e.g. `add`, `rm`). Do **not** use `--non-interactive` with `init`, which requires interactive input. | ||
|
|
||
| ## Commands | ||
|
|
||
| ### Create a Worktree | ||
|
|
||
| ```bash | ||
| "$GIT_WT" --non-interactive add <branch> [source-branch] | ||
| ``` | ||
|
|
||
| - Creates a worktree for `<branch>`, optionally from `[source-branch]` | ||
| - If the branch exists locally, checks it out into a new worktree | ||
| - If it exists only on `origin`, uses the remote branch (auto-confirmed with `--non-interactive`) | ||
| - If it doesn't exist anywhere, creates a new branch from HEAD or `[source-branch]` | ||
| - Runs any configured setup commands from `worktree.conf` / `worktree.conf.local` | ||
|
|
||
| **Examples:** | ||
| ```bash | ||
| # Create worktree for existing branch | ||
| "$GIT_WT" --non-interactive add feature/login | ||
|
|
||
| # Create worktree for new branch from master | ||
| "$GIT_WT" --non-interactive add feature/new-feature master | ||
|
|
||
| # Create worktree for new branch from specific base | ||
| "$GIT_WT" --non-interactive add bugfix/fix-123 release/v2 | ||
| ``` | ||
|
|
||
| ### List Worktrees | ||
|
|
||
| ```bash | ||
| "$GIT_WT" ls | ||
| ``` | ||
|
|
||
| Lists all worktrees (`git worktree list`). | ||
|
|
||
| ### Remove a Worktree | ||
|
|
||
| ```bash | ||
| "$GIT_WT" --non-interactive rm <branch> | ||
| "$GIT_WT" --non-interactive rm # Removes current worktree (auto-detected) | ||
| "$GIT_WT" --non-interactive rm --force <branch> # Force removal | ||
| ``` | ||
|
|
||
| - Runs any configured teardown commands before removal | ||
| - Without args, removes the current worktree if in one | ||
|
|
||
| ### Show Worktree Path | ||
|
|
||
| ```bash | ||
| "$GIT_WT" cd <branch> | ||
| ``` | ||
|
|
||
| Prints the filesystem path of the worktree for `<branch>`. Useful for scripting. | ||
|
|
||
| ### Initialize Configuration | ||
|
|
||
| ```bash | ||
| "$GIT_WT" init | ||
| ``` | ||
|
|
||
| Interactively creates `worktree.conf.local` in the repo root. **Note:** Do not use `--non-interactive` with this command — it requires user input to configure directories and setup commands. | ||
|
|
||
| ### Help | ||
|
|
||
| ```bash | ||
| "$GIT_WT" help | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| The script uses two shell-sourceable config files in each project's repo root: | ||
|
|
||
| **`worktree.conf`** (committed project defaults): | ||
| ```bash | ||
| WORKTREE_DIR=".." | ||
| WORKTREE_PREFIX="myapp" | ||
| WORKTREE_SETUP=("./setup.sh") | ||
| WORKTREE_TEARDOWN=("./teardown.sh") | ||
| ``` | ||
|
|
||
| **`worktree.conf.local`** (personal overrides, gitignored): | ||
| ```bash | ||
| WORKTREE_DIR="/home/me/worktrees" | ||
| WORKTREE_SETUP=("./setup.sh" "direnv allow") | ||
| WORKTREE_TEARDOWN=("docker compose down") | ||
| ``` | ||
|
|
||
| ### Variables | ||
|
|
||
| | Variable | Default | Description | | ||
| |---|---|---| | ||
| | `WORKTREE_DIR` | `..` | Base directory for worktrees (relative to repo root) | | ||
| | `WORKTREE_PREFIX` | repo name | Prefix for worktree directory names | | ||
| | `WORKTREE_SETUP` | `()` | Commands to run after creating a worktree | | ||
| | `WORKTREE_TEARDOWN` | `()` | Commands to run before removing a worktree | | ||
|
|
||
| ### Directory Naming | ||
|
|
||
| Format: `<base>/<prefix>-<sanitized-branch>` | ||
|
|
||
| Branch `feature/login` with prefix `myapp` and base `..`: | ||
| ``` | ||
| ../myapp-feature-login | ||
| ``` | ||
|
|
||
| Sanitization: `/` becomes `-`, everything lowercased. | ||
|
|
||
| ## Typical Workflow | ||
|
|
||
| 1. **Fetch git-wt**: | ||
| ```bash | ||
| GIT_WT="$("$SKILL_DIR/scripts/ensure-git-wt.sh")" | ||
| ``` | ||
| 2. **Create worktree** for a feature branch: | ||
| ```bash | ||
| "$GIT_WT" --non-interactive add feature/my-branch master | ||
| ``` | ||
| 3. **Work in the worktree** directory (printed as the last line of output) | ||
| 4. **List worktrees** to see all active ones: | ||
| ```bash | ||
| "$GIT_WT" ls | ||
| ``` | ||
| 5. **Clean up** when done: | ||
| ```bash | ||
| "$GIT_WT" --non-interactive rm feature/my-branch | ||
| ``` | ||
|
|
||
| ## Source | ||
|
|
||
| Fetched from [vojtabiberle/git-wt](https://github.com/vojtabiberle/git-wt) (MIT License). |
34 changes: 34 additions & 0 deletions
34
plugins/developer/skills/git-worktree/scripts/ensure-git-wt.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # ensure-git-wt.sh — Clone or update the git-wt repo, then print its path. | ||
| # Usage: GIT_WT="$(./ensure-git-wt.sh)" | ||
|
|
||
| readonly GIT_WT_REPO="https://github.com/vojtabiberle/git-wt.git" | ||
| readonly GIT_WT_PINNED_COMMIT="f44fbfe042b6f454e0016d5e844d773073600074" | ||
| readonly GIT_WT_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/git-wt" | ||
|
|
||
| if [[ -d "$GIT_WT_DIR/.git" ]]; then | ||
| # Try to update existing clone; on failure, warn and keep using current version. | ||
| if ! git -C "$GIT_WT_DIR" fetch --quiet >&2 || \ | ||
| ! git -C "$GIT_WT_DIR" checkout --quiet "$GIT_WT_PINNED_COMMIT" >&2; then | ||
| echo "Warning: Failed to update git-wt in '$GIT_WT_DIR'; using existing version." >&2 | ||
| fi | ||
| else | ||
| # Clone fresh; on failure, provide a helpful error and exit. | ||
| if ! git clone --quiet "$GIT_WT_REPO" "$GIT_WT_DIR" >&2; then | ||
| echo "Error: Failed to clone git-wt from '$GIT_WT_REPO' into '$GIT_WT_DIR'." >&2 | ||
| echo "Please check your network connection and repository access, then try again." >&2 | ||
| exit 1 | ||
| fi | ||
| git -C "$GIT_WT_DIR" checkout --quiet "$GIT_WT_PINNED_COMMIT" >&2 || true | ||
| fi | ||
|
|
||
| # Verify the executable exists | ||
| if [[ ! -f "$GIT_WT_DIR/git-wt" ]]; then | ||
| echo "ensure-git-wt.sh: expected git-wt executable not found at '$GIT_WT_DIR/git-wt'" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Print the path to the git-wt executable on stdout | ||
| echo "$GIT_WT_DIR/git-wt" | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.