From d0bf95cb6db0f3582ae9cd7649da4002bc72155d Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Tue, 3 Feb 2026 19:34:10 -0800 Subject: [PATCH] fix: more branch shit --- src/services/gitService.ts | 42 ++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/services/gitService.ts b/src/services/gitService.ts index 13ddd65..aa58423 100644 --- a/src/services/gitService.ts +++ b/src/services/gitService.ts @@ -213,18 +213,16 @@ const cloneRepository = async( }; /** - * Handles updating an existing branch with a newer version. - * @param options - The branch update options. - * @returns The update result. + * Deletes a stale local branch if it exists. + * @param logger - The logger instance. + * @param repoPath - Path to the repository. + * @param branchName - Name of the branch to delete. */ -const handleExistingBranch = async( - options: BranchUpdateOptions, -): Promise => { - const { branchName, clonedRepo, logger, packageName, targetVersion } - = options; - const { path: repoPath } = clonedRepo; - - // Delete local branch if it exists (stale from previous run) +const deleteStaleLocalBranch = async( + logger: Logger, + repoPath: string, + branchName: string, +): Promise => { const localBranchOutput = await runGitCommand(logger, repoPath, "git branch"); const localBranchNames = localBranchOutput. split("\n"). @@ -237,6 +235,28 @@ const handleExistingBranch = async( if (localBranchNames.includes(branchName)) { await runGitCommand(logger, repoPath, `git branch -D ${branchName}`); } +}; + +/** + * Handles updating an existing branch with a newer version. + * @param options - The branch update options. + * @returns The update result. + */ +const handleExistingBranch = async( + options: BranchUpdateOptions, +): Promise => { + const { branchName, clonedRepo, logger, packageName, targetVersion } + = options; + const { path: repoPath } = clonedRepo; + + await deleteStaleLocalBranch(logger, repoPath, branchName); + + // Fetch the specific branch to ensure we have the latest refs + await runGitCommand( + logger, + repoPath, + `git fetch origin ${branchName}:refs/remotes/origin/${branchName}`, + ); await runGitCommand( logger,