Skip to content

fix sync --all failing when deleted branch exists in tree#685

Open
willschnicke-silkline wants to merge 1 commit intoaviator-co:masterfrom
willschnicke-silkline:will/will/fix-restack-deleted-branch
Open

fix sync --all failing when deleted branch exists in tree#685
willschnicke-silkline wants to merge 1 commit intoaviator-co:masterfrom
willschnicke-silkline:will/will/fix-restack-deleted-branch

Conversation

@willschnicke-silkline
Copy link
Copy Markdown
Contributor

WHY
av sync --all --rebase-to-trunk crashes with error: git merge-base: exit status 128 when a branch has been deleted from git but not yet cleaned up with av tidy. This happens because GetTargetBranches includes all branches from av's metadata DB without checking if the git refs still exist.

WHAT
added ref existence checks in GetTargetBranches for AllBranches mode — branches whose git refs no longer exist are silently skipped instead of being passed to the sequencer where they'd cause git merge-base to fail.

TESTING

  • added e2e test that creates a deleted-but-not-tidied branch and verifies sync --all --rebase-to-trunk succeeds
  • all existing sync and restack e2e tests pass

@willschnicke-silkline willschnicke-silkline requested a review from a team as a code owner March 27, 2026 00:30
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Mar 27, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Mar 27, 2026

🔃 FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • 🔒 aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • 🔒 e2e_tests/sync_all_deleted_branch_test.go
    • 🔒 internal/sequencer/planner/targets.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app bot requested a review from davi-maciel March 27, 2026 00:30
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix to prevent av sync --all from failing when a branch tracked in metadata has been deleted from Git. It includes an E2E test and updates GetTargetBranches to verify branch existence. The review feedback points out that errors from repo.DoesRefExist are ignored, which could lead to silent failures; handling these errors is recommended to ensure the tool behaves correctly during Git communication issues.

Comment on lines +46 to +49
ref := plumbing.NewBranchReferenceName(br.Name)
if exists, _ := repo.DoesRefExist(ctx, ref.String()); exists {
ret = append(ret, ref)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The error returned by repo.DoesRefExist is being ignored. If DoesRefExist encounters an error (e.g., a problem communicating with Git), exists will be false, and the branch will be silently skipped. This can lead to incorrect behavior where branches are skipped due to an error rather than actual deletion. Errors should be handled explicitly, either by propagating them or logging them appropriately, to prevent silent failures.

ref := plumbing.NewBranchReferenceName(br.Name)
if exists, err := repo.DoesRefExist(ctx, ref.String()); err != nil {
	return nil, errors.Wrapf(err, "failed to check existence of branch %q", br.Name)
} else if exists {
	ret = append(ret, ref)
}

Comment on lines +53 to +56
ref := plumbing.NewBranchReferenceName(n)
if exists, _ := repo.DoesRefExist(ctx, ref.String()); exists {
ret = append(ret, ref)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Similar to the previous comment, the error returned by repo.DoesRefExist is ignored here. This can lead to branches being incorrectly skipped if there's an underlying issue with Git communication, rather than the branch truly not existing. It's important to handle errors explicitly to ensure the correct behavior of the sync --all operation.

ref := plumbing.NewBranchReferenceName(n)
if exists, err := repo.DoesRefExist(ctx, ref.String()); err != nil {
	return nil, errors.Wrapf(err, "failed to check existence of branch %q", n)
} else if exists {
	ret = append(ret, ref)
}

@davi-maciel davi-maciel requested review from tulioz and removed request for davi-maciel March 27, 2026 00:37
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.

1 participant