Repository navigation
Fix #3755: avoid creating orphan branch when push_files fails - #3778
Open
genius-0963 wants to merge 1 commit into
Open
genius-0963 wants to merge 1 commit into
genius-0963 wants to merge 1 commit into
Conversation
When push_files targets a non-existent branch, it previously created the branch reference pointing to the default branch head before creating the tree and commit. If tree or commit creation subsequently failed (e.g. due to a malformed path or API error), the newly created branch reference was left behind at the default branch head. This commit defers branch reference creation until after the tree and commit have been successfully created, pointing the new branch reference directly at the new commit SHA. If tree or commit creation fails, no branch reference is created in the repository. Fixes github#3755
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change that defers new branch creation until after commit creation.
No open issues 🎉
What changed in this PR
Addresses #3755 by delaying new branch creation in push_files until the tree and commit are successfully created, preventing failed pushes from leaving an orphan branch reference.
Changes:
- Creates new branch references directly at the completed commit while preserving the update path for existing branches.
- Removes the unused helper that created branches upfront.
- Adds tests for successful new-branch pushes and tree or commit creation failures.
| File | Description |
|---|---|
pkg/github/repositories.go |
Defers new branch reference creation until after commit creation. |
pkg/github/repositories_test.go |
Adds new-branch success and failure regression tests. |
pkg/github/repositories_helper.go |
Removes the obsolete branch-creation helper. |
Review effort: Balanced (auto)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Avoids leaving behind an orphan branch pointing at the default branch's HEAD when
push_filesfails during tree or commit creation.Why
Fixes #3755
When
push_filespushed to a branch that did not exist, it previously created the new branch reference pointing to the default branch's HEAD commit upfront before creating the tree and commit. If creating the tree (e.g. malformed path component) or creating the commit failed, the new branch reference was not rolled back, leaving behind an orphan branch at the default branch's HEAD.What changed
pkg/github/repositories.go(PushFiles), deferred branch reference creation for new branches until after the tree and commit objects have been successfully created.client.Git.CreateRef, eliminating the orphan branch creation when tree or commit operations fail.createReferenceFromDefaultBranchinpkg/github/repositories_helper.go.pkg/github/repositories_test.gocovering successful push to a new branch, tree creation failure on a new branch (ensuring no branch ref is created), and commit creation failure on a new branch (ensuring no branch ref is created).MCP impact
push_filesbehavior is improved so that failed pushes to a non-existent branch leave the repository unchanged without leaving an orphan branch reference. The tool schema and output types remain unchanged.Prompts tested (tool changes only)
Security / limits
Tool renaming
Lint & tests
./script/lint./script/testDocs