Skip to content

feat(worktree): auto-configure branch tracking on post-checkout (PP-ozw)#1282

Open
timothyfroehlich wants to merge 4 commits intomainfrom
feat/pp-ozw-worktree-branch-tracking
Open

feat(worktree): auto-configure branch tracking on post-checkout (PP-ozw)#1282
timothyfroehlich wants to merge 4 commits intomainfrom
feat/pp-ozw-worktree-branch-tracking

Conversation

@timothyfroehlich
Copy link
Copy Markdown
Owner

Summary

  • Adds configure_branch_tracking(branch, worktree_path) to scripts/worktree_setup.py, called from main() after get_branch().
  • If origin/<branch> exists: sets local upstream via git branch --set-upstream-to=origin/<branch>.
  • Otherwise: prints a stderr reminder to run git push -u origin <branch> after first commit.
  • Skips main/master/HEAD; never auto-pushes; tolerates transient git failures (warn, don't crash).

Why

git worktree add /path -b new-branch origin/main leaves new-branch's 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. This PR closes that gap so new worktrees are immediately ready for normal git pull/git push against the right remote branch.

Manual verification

  • ✅ New local-only branch → reminder printed.
  • ✅ Branch with existing remote → upstream set, confirmation printed.
  • main / HEAD → silently skipped.
  • pnpm run check clean (1013 unit tests).
  • ruff check and ruff format --check pass.

Inherited CI failures

main is 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

  • Unit tests pass
  • Function tested manually for all four branch-state scenarios
  • CI Gate green
  • Verify on next worktree creation that the reminder/upstream-set message appears in the post-checkout output

Related

  • Child 5 of epic PP-2on
  • PP-uc8 / PP-6dp / PP-cao / PP-278 / PP-00s queued as siblings

🤖 Generated with Claude Code

`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>
Copilot AI review requested due to automatic review settings May 5, 2026 01:13
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pin-point Ready Ready Preview, Comment May 5, 2026 7:58pm

@supabase
Copy link
Copy Markdown

supabase Bot commented May 5, 2026

This pull request has been ignored for the connected project udhesuizjsgxfeotqybn due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 whether origin/<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.

Comment thread scripts/worktree_setup.py
Comment thread scripts/worktree_setup.py
Comment on lines 589 to +590
branch = get_branch()
configure_branch_tracking(branch, worktree_path)
Comment thread scripts/worktree_setup.py
Comment on lines +514 to +518
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
@timothyfroehlich
Copy link
Copy Markdown
Owner Author

⚠️ CI Status — Known-Broken Specs (Do Not Fix Here)

Multiple E2E specs are currently failing on main and inheriting onto every open PR. If you are an AI agent: do NOT attempt to fix these failures in this PR — dedicated beads track each one. Fixing them here will create merge conflicts and duplicate work.

Known-broken (leave alone):

What you CAN fix:

Failures specific to this PR's diff (anything not in the list above). When in doubt, leave for human review.

Status:

—Claude (lead orchestrator, 2026-05-04)

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.
Copilot AI review requested due to automatic review settings May 5, 2026 19:55
@timothyfroehlich timothyfroehlich added the ready-for-review PR passed CI and has no unresolved review comments label May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review PR passed CI and has no unresolved review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants