From d2a6ddb05955c9d078d82b042e0cd2478e712ae6 Mon Sep 17 00:00:00 2001 From: gastown/polecats/furiosa Date: Wed, 31 Dec 2025 13:11:17 -0800 Subject: [PATCH] fix: gt done handles missing origin tracking ref in worktrees (gt-cehl8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In worktrees, git push -u origin may not create the local refs/remotes/origin/ tracking ref due to missing refspecs. BranchPushedToRemote now explicitly creates the remote tracking ref from FETCH_HEAD after fetching if it does not exist locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/git/git.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/git/git.go b/internal/git/git.go index 77300fea..6cdbdbc6 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -745,7 +745,18 @@ func (g *Git) BranchPushedToRemote(localBranch, remote string) (bool, int, error // Remote branch exists - fetch to ensure we have the local tracking ref // This handles the case where we just pushed and origin/branch doesn't exist locally yet - _, _ = g.run("fetch", remote, localBranch) + _, fetchErr := g.run("fetch", remote, localBranch) + + // In worktrees, the fetch may not update refs/remotes/origin/ due to + // missing refspecs. If the remote ref doesn't exist locally, create it from FETCH_HEAD. + // See: gt-cehl8 (gt done fails in worktrees due to missing origin tracking ref) + remoteRef := "refs/remotes/" + remoteBranch + if _, err := g.run("rev-parse", "--verify", remoteRef); err != nil { + // Remote ref doesn't exist locally - update it from FETCH_HEAD if fetch succeeded + if fetchErr == nil { + _, _ = g.run("update-ref", remoteRef, "FETCH_HEAD") + } + } // Check if local is ahead count, err := g.run("rev-list", "--count", remoteBranch+"..HEAD")