Skip to content

fix(newTree.fsx): crash if remote branch disappears#326

Open
nodefect wants to merge 1 commit into
tarsgate:masterfrom
nodefect:fix-newTree-stale-branches
Open

fix(newTree.fsx): crash if remote branch disappears#326
nodefect wants to merge 1 commit into
tarsgate:masterfrom
nodefect:fix-newTree-stale-branches

Conversation

@nodefect

Copy link
Copy Markdown
Contributor

Problem
newTree.fsx crashes with fatal: couldn't find remote ref refs/heads/someBranch when a previously-tracked remote branch is deleted (e.g. after a PR is merged).

Cause
The script used git remote set-branches --add \u003cremote\u003e \u003cbranch\u003e once per branch. Since --add is cumulative, deleted branches stayed in the refspec forever and git fetch --all later tried (and failed) to fetch them.

Fix

  1. Introduce GetExistingWorktreeBranches — inspects git worktree list --porcelain so we know which branches existing local worktrees depend on.
  2. Build a single list of candidate branches: worktree branches + head branch + target branch.
  3. For each remote, filter that list to branches that still exist (git ls-remote).
  4. Run one git remote set-branches \u003cremote\u003e \u003cbranch\u003e… (without --add) per remote. This resets the refspec to exactly the branches that still exist, clearing any stale entries.

Closes #325

Replace per-branch 'git remote set-branches --add' with a
single per-remote 'git remote set-branches' (without --add)
that resets the tracked branches to only those that still exist.

This fixes the crash when a previously-tracked remote branch is
deleted (e.g. after a PR is merged), because 'git fetch --all' no
longer tries to fetch stale refs.

To avoid breaking existing worktrees, we now also inspect the
branches currently used by local worktrees (via 'git worktree list
--porcelain') and include them in the set of branches to track.

Closes tarsgate#325
@github-actions

Copy link
Copy Markdown

⚠️ CI Build Failed!

Hey @nodefect, one or more CI jobs failed. Please check the workflow logs.

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.

bug(newTree.fsx): crash if remote branch disappears

1 participant