feat: add worktree pull command and worktree-aware CLAUDE.md - #4
Conversation
…tion Add `worktree pull` subcommand to pull all git repositories under the current directory in bulk. Works from both project root and worktree directories. Also add `generate_worktree_claude_md()` to prepend worktree context (task name, working directory, project root) to CLAUDE.md when creating worktrees, so agents retain context after /compact. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 18 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughこのプルリクエストは、ネストされたGitリポジトリ全体に対して一括で Changes
Sequence DiagramsequenceDiagram
participant User
participant Main as worktree (main)
participant CmdPull as cmd_pull
participant Git as git repositories
participant Logger as Logging Output
User->>Main: worktree pull
Main->>CmdPull: cmd_pull "$@"
activate CmdPull
CmdPull->>CmdPull: Parse arguments & validate
CmdPull->>CmdPull: get_project_root
CmdPull->>CmdPull: get_project_name
CmdPull->>CmdPull: list_git_repos
CmdPull->>Logger: Print section headers
loop For each repository
CmdPull->>Logger: Log current branch
CmdPull->>Git: git pull
Git-->>CmdPull: Return status & output
CmdPull->>CmdPull: Parse output ("Already up to date" or update)
CmdPull->>Logger: Log success/update message
CmdPull->>CmdPull: Record status in RESULTS array
end
CmdPull->>Logger: print_summary RESULTS
CmdPull-->>Main: Return status
deactivate CmdPull
Main-->>User: Command output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
lib/cmd_pull.sh (2)
75-80: detached HEAD 状態の考慮
git branch --show-currentは detached HEAD 状態では空文字列を返します。現在のコードはこれを適切に処理していますが、detached HEAD であることをユーザーに明示的に通知すると親切です。💡 提案: detached HEAD の明示
local current_branch current_branch="$(git -C "$repo_path" branch --show-current 2>/dev/null)" if [ -n "$current_branch" ]; then log_info " ブランチ: ${current_branch}" + else + log_warn " detached HEAD 状態です" fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/cmd_pull.sh` around lines 75 - 80, When current_branch (from current_branch="$(git -C "$repo_path" branch --show-current 2>/dev/null)") is empty, detect detached HEAD and log it: call git -C "$repo_path" rev-parse --short HEAD (or git -C "$repo_path" symbolic-ref -q --short HEAD) to obtain the commit id and then use log_info to print a message like "ブランチ: detached HEAD (commit <short-hash>)" instead of skipping output; update the logic around current_branch and the log_info call so detached HEAD is explicitly reported while preserving existing behavior for normal branches.
82-96:git pullのマージ動作を検討してください
git pullはデフォルトでマージコミットを作成する可能性があります。意図しないマージコミットを避けるため、--ff-onlyオプションの使用を検討してください。また、detached HEAD 状態やアップストリームが設定されていないブランチでは
git pullが失敗する可能性がありますが、現在のエラーハンドリングで対応されています。♻️ 提案: --ff-only オプションの使用
# git pull local pull_output - if pull_output=$(git -C "$repo_path" pull 2>&1); then + if pull_output=$(git -C "$repo_path" pull --ff-only 2>&1); then if echo "$pull_output" | grep -q "Already up to date"; thenfast-forward できない場合は失敗として扱われ、ユーザーが手動で対処できます。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/cmd_pull.sh` around lines 82 - 96, Replace the plain git pull invocation with a fast-forward-only pull to avoid creating unintended merge commits: update the git command in the block that captures pull_output (the line using pull_output=$(git -C "$repo_path" pull 2>&1)) to use --ff-only, and keep the existing error branch (which populates RESULTS["$repo"] and logs via log_error) so fast-forward failures are treated as errors requiring manual intervention; no other control flow changes are needed.lib/common.sh (1)
58-88: ソースファイルの存在チェックがない
$srcが存在しない場合、cat "$src"は失敗しますが、$dstファイルは部分的に作成されてしまいます(heredoc 部分のみ)。呼び出し元で存在チェックを行っているか確認するか、この関数内でバリデーションを追加することを検討してください。🛡️ 提案: ソースファイルの存在チェックを追加
generate_worktree_claude_md() { local src="$1" local dst="$2" local task_name="$3" local task_dir="$4" local project_root="$5" + if [ ! -f "$src" ]; then + log_warn "CLAUDE.md が見つかりません: ${src}" + return 1 + fi + { cat <<WORKTREE_CONTEXT🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/common.sh` around lines 58 - 88, The generate_worktree_claude_md function writes a heredoc then cats $src into $dst without verifying $src exists, which can leave a partially-created $dst; modify generate_worktree_claude_md to first validate that the source file (parameter src) exists and is readable, and if not return a non-zero status and do not create/overwrite dst; to avoid partial writes, write the combined content to a temporary file (e.g., in the same directory) and atomically mv it to dst only after successful cat, and ensure any error paths clean up the temp file and propagate a clear error message/exit code so callers can handle the failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/cmd_pull.sh`:
- Around line 75-80: When current_branch (from current_branch="$(git -C
"$repo_path" branch --show-current 2>/dev/null)") is empty, detect detached HEAD
and log it: call git -C "$repo_path" rev-parse --short HEAD (or git -C
"$repo_path" symbolic-ref -q --short HEAD) to obtain the commit id and then use
log_info to print a message like "ブランチ: detached HEAD (commit <short-hash>)"
instead of skipping output; update the logic around current_branch and the
log_info call so detached HEAD is explicitly reported while preserving existing
behavior for normal branches.
- Around line 82-96: Replace the plain git pull invocation with a
fast-forward-only pull to avoid creating unintended merge commits: update the
git command in the block that captures pull_output (the line using
pull_output=$(git -C "$repo_path" pull 2>&1)) to use --ff-only, and keep the
existing error branch (which populates RESULTS["$repo"] and logs via log_error)
so fast-forward failures are treated as errors requiring manual intervention; no
other control flow changes are needed.
In `@lib/common.sh`:
- Around line 58-88: The generate_worktree_claude_md function writes a heredoc
then cats $src into $dst without verifying $src exists, which can leave a
partially-created $dst; modify generate_worktree_claude_md to first validate
that the source file (parameter src) exists and is readable, and if not return a
non-zero status and do not create/overwrite dst; to avoid partial writes, write
the combined content to a temporary file (e.g., in the same directory) and
atomically mv it to dst only after successful cat, and ensure any error paths
clean up the temp file and propagate a clear error message/exit code so callers
can handle the failure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8d95941f-cc3b-4cbd-9bc9-dc413fea67b6
📒 Files selected for processing (4)
lib/cmd_create.shlib/cmd_pull.shlib/common.shworktree
There was a problem hiding this comment.
Code Review
This pull request adds a pull subcommand to the worktree tool for bulk updating git repositories and updates the create command to generate a CLAUDE.md file containing worktree-specific context. A suggestion was made to use LC_ALL=C and --ff-only with git pull to ensure consistent output parsing and prevent the script from hanging on interactive merges.
Address review feedback: --ff-only prevents interactive merge/rebase from hanging the script, and LC_ALL=C ensures "Already up to date" string matching is locale-independent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
worktree pullsubcommand to bulk-pull all git repositories under the current directory (works from both project root and worktree directories)generate_worktree_claude_md()to prepend worktree context (task name, working directory, project root) to CLAUDE.md during worktree creation, so agents retain context after/compactTest plan
worktree pull --helpでヘルプが表示されることworktree pullを実行し、配下の全リポジトリが pull されることworktree pullを実行し、配下の全リポジトリが pull されることworktree create <task>で CLAUDE.md にワークツリーコンテキストが付加されること🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
pullコマンドを追加しました。プロジェクト内の全リポジトリに対してgit pullを一括実行できます。CLAUDE.mdをワークツリーコンテキスト情報付きで自動生成するようになりました。これにより、タスク情報やプロジェクト構造が埋め込まれます。