Skip to content

worktree script#1737

Merged
simo6529 merged 2 commits intomainfrom
worktree-script
Jan 14, 2026
Merged

worktree script#1737
simo6529 merged 2 commits intomainfrom
worktree-script

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Jan 14, 2026

Summary by CodeRabbit

  • New Features

    • Added a worktree synchronization system with configurable symlink and per-worktree copy modes, plus a CLI to sync all or specific worktrees (dry-run, verbose, help).
  • Chores

    • Broadened .gitignore patterns to cover both files and directories.
    • Improved worktree creation flow with robust path handling and delegated sync workflow for consistent setup.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 14, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a git worktree synchronization system: two declarative configs (symlink and copy), a new wt-sync.sh to apply them across worktrees, and updates wt-add.sh to invoke the synchronizer and use explicit repository-root paths. Also tightens .gitignore patterns.

Changes

Cohort / File(s) Summary
Gitignore Pattern Updates
.\.gitignore
Removed trailing slashes from several patterns so rules apply to both files and directories (e.g., .cursor/.cursor). Removed trailing blank line.
Worktree Configs
scripts/worktree/copy.conf, scripts/worktree/sync.conf
Added declarative config files: sync.conf lists paths to symlink from the main repo; copy.conf lists paths to copy per worktree. Comments explain format and examples.
Worktree Sync Script
scripts/worktree/wt-sync.sh
New Bash script implementing synchronization for worktrees: parses configs, discovers non-main worktrees, creates relative symlinks for shared items, copies per-worktree items, supports dry-run/verbose, and handles errors/edge cases.
Worktree Add Script Updates
scripts/worktree/wt-add.sh
Updated to compute SCRIPT_DIR/MAIN_REPO/WORKTREE_PATH, run Git commands with -C, invoke wt-sync.sh instead of direct .env copying, and place VS Code settings, pre-commit hooks, and npm install operations in the computed worktree path.

Sequence Diagram

sequenceDiagram
    participant User
    participant wt-add.sh
    participant Git
    participant wt-sync.sh
    participant Configs
    participant Worktree
    User->>wt-add.sh: run wt-add <name>
    wt-add.sh->>wt-add.sh: resolve SCRIPT_DIR, MAIN_REPO, WORKTREE_PATH
    wt-add.sh->>Git: git -C MAIN_REPO worktree add <WORKTREE_PATH>
    Git->>Worktree: create worktree
    wt-add.sh->>wt-sync.sh: wt-sync.sh --worktree <WORKTREE_PATH>
    wt-sync.sh->>Configs: read sync.conf and copy.conf
    wt-sync.sh->>Worktree: create relative symlinks for shared files
    wt-sync.sh->>Worktree: copy per-worktree files
    wt-sync.sh->>wt-add.sh: return status
    wt-add.sh->>Worktree: write VS Code settings, install hooks, run npm install
    wt-add.sh->>User: report completion
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hop to sync each branch and tree,
Symlinks stitch where copies flee,
New configs hum, scripts align,
Worktrees flourish, paths defined,
A tiny rabbit cheers: "All set — that's fine!"

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'worktree script' is overly vague and generic, using non-descriptive language that doesn't convey meaningful information about the specific changes made in this PR. Provide a more specific title that describes the main change, such as 'Add worktree synchronization scripts and configuration' or 'Implement git worktree management tools with sync and copy modes'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 945d525 and bae31b0.

📒 Files selected for processing (1)
  • scripts/worktree/wt-add.sh

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Simo <simo@6529.io>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/worktree/wt-add.sh (1)

46-46: Invalid JSON comment syntax.

Line 46 has / --- Formatting --- but JSON comments in VS Code settings use //. This will cause a JSON parse error when VS Code loads the settings.

🐛 Proposed fix
-  / --- Formatting ---
+  // --- Formatting ---
🤖 Fix all issues with AI agents
In `@scripts/worktree/wt-sync.sh`:
- Around line 120-131: The relative symlink logic in wt-sync.sh currently builds
relative_source as "../$MAIN_REPO_NAME/$rel_path", which fails when worktrees
aren’t direct siblings; replace that naive construction with a robust
relative-path computation (e.g., use realpath --relative-to "$target_dir"
"$source" and fall back to a short Python snippet when realpath --relative-to is
unavailable) to set relative_source, and when checking existing symlink targets
(readlink "$target") normalize/resolve both sides before comparison so
comparisons handle absolute vs relative links correctly; update the block that
computes target_dir/relative_source and the readlink comparison to use the new
computed relative path and normalization.
🧹 Nitpick comments (2)
scripts/worktree/wt-sync.sh (2)

121-121: Declare and assign variables separately to avoid masking return values.

ShellCheck SC2155: When you use local var=$(command), a failing command's exit status is masked by local's success. Separate declaration from assignment to preserve error handling with set -e.

♻️ Proposed fixes
     # Calculate relative path from target's parent to source
-    local target_dir=$(dirname "$target")
+    local target_dir
+    target_dir=$(dirname "$target")
     local relative_source="../$MAIN_REPO_NAME/$rel_path"
 
     # Already a correct symlink?
     if [[ -L "$target" ]]; then
-        local current=$(readlink "$target")
+        local current
+        current=$(readlink "$target")
         if [[ "$current" == "$relative_source" || "$current" == "$source" ]]; then

At line 190:

     # Create parent directory if needed
-    local target_dir=$(dirname "$target")
+    local target_dir
+    target_dir=$(dirname "$target")
     if [[ ! -d "$target_dir" ]]; then

At line 211:

 sync_worktree() {
     local worktree_path="$1"
-    local worktree_name=$(basename "$worktree_path")
+    local worktree_name
+    worktree_name=$(basename "$worktree_path")

Also applies to: 126-126, 190-190, 211-211


100-102: Consider safer whitespace trimming.

Using xargs for whitespace trimming can misbehave with paths containing quotes, backslashes, or special characters. A pure-bash approach is safer.

♻️ Suggested safer whitespace trimming
         # Trim whitespace
-        line=$(echo "$line" | xargs)
+        line="${line#"${line%%[![:space:]]*}"}"  # trim leading
+        line="${line%"${line##*[![:space:]]}"}"  # trim trailing
         [[ -n "$line" ]] && echo "$line"
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a53b1e and 945d525.

📒 Files selected for processing (5)
  • .gitignore
  • scripts/worktree/copy.conf
  • scripts/worktree/sync.conf
  • scripts/worktree/wt-add.sh
  • scripts/worktree/wt-sync.sh
🧰 Additional context used
🪛 Shellcheck (0.11.0)
scripts/worktree/wt-sync.sh

[warning] 121-121: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 126-126: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 190-190: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 211-211: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (8)
.gitignore (1)

97-97: LGTM! Broadening ignore patterns for AI assistant files is appropriate.

The change adds general patterns (.cursor, .claude, .codex, .gemini) that ignore both files and directories with these names, consistent with how other editor-related entries are handled (.idea and .vscode on lines 68-69). No tracked files match these patterns, so there are no unintended consequences.

scripts/worktree/copy.conf (1)

1-10: LGTM!

The configuration file is well-documented with clear format instructions. Using COPY mode for .env.development is appropriate since each worktree may need independent environment configurations.

scripts/worktree/wt-sync.sh (2)

80-87: LGTM!

The worktree discovery logic correctly filters out the main repo and handles the porcelain output format properly.


249-294: LGTM!

The main function properly handles both single worktree targeting and batch synchronization. The worktree path resolution aligns with how wt-add.sh creates worktrees as siblings of the main repo.

scripts/worktree/wt-add.sh (3)

4-6: LGTM!

Good use of robust path resolution to establish SCRIPT_DIR, MAIN_REPO, and PARENT_DIR. This ensures the script works correctly regardless of the current working directory.


29-31: LGTM!

Clean delegation to wt-sync.sh for file synchronization, keeping concerns separated between worktree creation and file syncing.


118-134: LGTM!

The pre-commit hook setup correctly uses worktree-specific configuration with extensions.worktreeConfig and --worktree flag, ensuring the hook configuration doesn't affect other worktrees.

scripts/worktree/sync.conf (1)

14-19: These entries do not yet exist in the repository, so the directory format cannot be verified.

The sync.conf format documentation (lines 5–7) correctly specifies that directories require a trailing slash. However, all entries listed in lines 14–19 (.coderabbit.yml, .claude, CLAUDE.md, .codex, AGENTS.md, .gemini) are not found in the repository. When these entries are added, ensure that any directories include a trailing slash per the documented format.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread scripts/worktree/wt-sync.sh
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 14, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
19 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@simo6529 simo6529 merged commit 72fd1ec into main Jan 14, 2026
6 of 7 checks passed
@simo6529 simo6529 deleted the worktree-script branch January 14, 2026 08:52
@coderabbitai coderabbitai Bot mentioned this pull request Apr 9, 2026
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