Skip to content

worktree.sh: fall back to local origin/main when git fetch fails offline - #62

Merged
BunsDev merged 2 commits into
TypeSafeAI:mainfrom
Yash990-bit:fix-offline-worktree
Oct 3, 2026
Merged

BunsDev merged 2 commits into
TypeSafeAI:mainfrom
Yash990-bit:fix-offline-worktree

Conversation

@Yash990-bit

@Yash990-bit Yash990-bit commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #58

Summary

Allows scripts/worktree.sh new <name> and remove <name> to work offline by treating git fetch -q origin main as best-effort rather than aborting the script under set -e.

Changes

  1. new <name>: If fetching origin/main fails, git's error output remains visible on stderr alongside a note (note: could not fetch origin/main; using local ref), and the script falls back to cutting the branch from the local origin/main ref.
  2. remove <name>: If the fetch fails during removal, the script continues cleanly with || true and checks merge status against the local ref (which safely keeps unmerged branches).

Verification

  • Tested offline behavior locally; worktree creation proceeds using local origin/main ref with error diagnosis visible.
  • Rebased onto latest main and ran the full test suite (npm test: 147/147 passing).
  • Commit signed with verified SSH key.

@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Hi @BunsDev, could you take a look at this offline fallback fix for worktree.sh when you get some time? Verified with npm test and signed with SSH. Thank you!

@BunsDev BunsDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this makes sense. new now cuts from the local origin/main with a note instead of aborting under set -e. In remove, a stale origin/main can only make the merged check answer "not merged", which keeps the branch, so that's the safe direction. Modex itself reads only the last stdout line of worktree.sh new and looks at stderr only on failure, so the new note can't break worktree threads.

One suggestion: 2>/dev/null hides why the fetch failed, which could be offline, expired credentials or a different remote name. Leaving git's own error visible next to the note, or including it in the note, would make the stale-base case easier to diagnose.

CI: the one failure, supervisor death without a cleanup receipt never authorizes deletion with write EPIPE, is a known flake on the older main this run tested against. It's fixed on main by #64 and isn't related to this change.

Before merge

  • GitHub shows 0be1b8c as unverified (unknown_key), and main requires verified signatures. Add the SSH key you sign with as a Signing key under Settings → SSH and GPG keys. The rebase below then produces a verified commit.
  • main requires branches to be up to date, so please rebase onto the current main. That also picks up the #64 fix for the flaky test.

@Yash990-bit
Yash990-bit force-pushed the fix-offline-worktree branch from 0be1b8c to 0261596 Compare October 2, 2026 06:44
@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Thanks for the review and suggestion, @BunsDev!

I've updated the PR:

  1. Git Error Output Preserved: Removed 2>/dev/null from the fetch in scripts/worktree.sh new. Git's own error output is now visible on stderr next to the fallback note so users can easily distinguish between offline, network timeouts, or credential issues when a stale base is used.
  2. Rebased onto main: Rebased cleanly onto the current main (picking up the Terminal cleanup: a dead supervisor always reads as a missing receipt #64 and Terminals no longer leak a PTY each: node-pty 1.2.0-beta.15 #65 fixes), ran npm test with all 147 unit tests passing.
  3. Verified Signature: Signed the commit with the verified SSH signing key.

@Yash990-bit
Yash990-bit requested a review from BunsDev October 2, 2026 06:50

@BunsDev BunsDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed and verified with a simulated offline clone (origin pointed at an unresolvable host).

  • new: on main the script aborts with exit 128 and creates nothing. With this change git's error stays visible, the note prints, and the worktree is cut from the local origin/main.
  • remove, branch with no commits of its own: completes and deletes the branch. It's an ancestor of the local origin/main.
  • remove, branch with an unmerged commit: on main the script exits 128 after the worktree is already gone, before reporting the branch. With this change it finishes and keeps the branch (branch work kept (not merged into origin/main)). The ls-remote/gh checks also fail offline and resolve to "not merged", so the safe default holds.

The repo has no shell-test harness, so this manual run is the regression evidence. Cosmetic: the later ls-remote still prints one fatal: line during an offline remove. Thanks!

🤖 Generated with Claude Code

@BunsDev
BunsDev merged commit ef081ff into TypeSafeAI:main Oct 3, 2026
1 check passed
@Yash990-bit

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and verifying the offline behavior locally! Glad the fallback works safely in both new and remove. I’ll keep the cosmetic ls-remote output in mind for a follow-up. 🚀

BunsDev added a commit that referenced this pull request Oct 3, 2026
…67)

The three contributor bug fixes landed today: send rejections reach the
caller (#61), staged renames diff as renames (#60, with its follow-ups
noted), and worktree.sh survives a failed fetch (#62). #39's branding
images merged yesterday. Drop all four from "Open contributor PRs".

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

scripts/worktree.sh fails when working offline due to unhandled git fetch

2 participants