feat(worktree): auto-configure branch tracking on post-checkout (PP-ozw)#1282
feat(worktree): auto-configure branch tracking on post-checkout (PP-ozw)#1282timothyfroehlich wants to merge 4 commits intomainfrom
Conversation
`git worktree add /path -b new-branch origin/main` creates new-branch but leaves its upstream as origin/main, so later `git pull`/`git push` operate against main. AGENTS.md documents the manual `git push -u origin <branch>` fix but worktree_setup.py never automated it. Adds configure_branch_tracking(branch, worktree_path) called from main() right after get_branch(): - If origin/<branch> exists: `git branch --set-upstream-to=origin/<branch>` and confirm. - If not: print stderr reminder to run `git push -u origin <branch>` after first commit. - Skip for main/master/HEAD (detached state). - Never auto-push — that would create remote branches for throwaway local experiments. - Failures are non-fatal: warn and continue. Setup must not block on transient git issues. Verified scenarios manually: - New local-only branch → reminder printed. - Branch with existing remote → upstream set, confirmation printed. - main / HEAD → silently skipped. Refs PP-2on (epic). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
Pull request overview
This PR extends the worktree post-checkout setup flow to auto-correct git upstream tracking for non-main branches, aiming to make newly created worktrees safer to use for normal git pull/git push operations.
Changes:
- Adds
configure_branch_tracking()to detect whetherorigin/<branch>exists and either set upstream tracking or print a first-push reminder. - Invokes branch-tracking configuration from
main()as part of the existing post-checkout worktree setup flow. - Keeps the behavior non-fatal so worktree config generation can continue even if git tracking setup fails.
| branch = get_branch() | ||
| configure_branch_tracking(branch, worktree_path) |
| def configure_branch_tracking(branch: str, worktree_path: Path) -> None: | ||
| """Set local upstream tracking for the worktree branch. | ||
|
|
||
| `git worktree add /path -b new-branch origin/main` creates `new-branch` | ||
| pointing at origin/main but leaves the upstream as origin/main, so later |
|
Addresses Copilot review on #1282: - Post-checkout hook now checks current upstream before reconfiguring, so deliberately-set non-origin/main upstreams aren't clobbered on every branch switch. - Adds 9-scenario test coverage for upstream resolution + git stderr capture edge cases.
Drop unused subprocess and call imports from upstream-tracking tests, apply ruff format. Surfaced by pnpm run check after merging origin/main.
Summary
configure_branch_tracking(branch, worktree_path)toscripts/worktree_setup.py, called frommain()afterget_branch().origin/<branch>exists: sets local upstream viagit branch --set-upstream-to=origin/<branch>.git push -u origin <branch>after first commit.main/master/HEAD; never auto-pushes; tolerates transient git failures (warn, don't crash).Why
git worktree add /path -b new-branch origin/mainleavesnew-branch's upstream asorigin/main, so latergit pull/git pushoperate against main. AGENTS.md documents the manualgit push -u origin <branch>fix but worktree_setup.py never automated it. This PR closes that gap so new worktrees are immediately ready for normalgit pull/git pushagainst the right remote branch.Manual verification
main/HEAD→ silently skipped.pnpm run checkclean (1013 unit tests).ruff checkandruff format --checkpass.Inherited CI failures
mainis currently red. Inherited failures from main (PP-q9r/PP-e20/PP-jsh/PP-v7g/PP-49m) will appear in CI; not introduced by this PR. See Tim's status comment on PR #1278.Test plan
Related
🤖 Generated with Claude Code