-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Improvements to push_files tool #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the push_files tool to automatically handle two common failure scenarios: empty repositories and non-existent branches. Instead of failing when encountering these conditions, the tool now initializes empty repositories with an initial commit and creates missing branches from the default branch.
Key changes:
- Added auto-initialization of empty repositories when a 409 Conflict status is detected
- Added auto-creation of branches from the default branch when a branch is not found
- Improved error handling and resource cleanup with nil checks before closing response bodies
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/github/repositories.go | Implements auto-init logic for empty repositories and auto-creation of non-existent branches; adds two helper functions initializeRepository and createReferenceFromDefaultBranch |
| pkg/github/repositories_test.go | Adds comprehensive test coverage for empty repository scenarios, branch auto-creation failures, and updates existing test expectations to match new behavior |
77142a8 to
bf28276
Compare
44a21fd to
7ea39cc
Compare
SamMorrowDrums
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's too big for me to review while off, but really nice improvement!
SamMorrowDrums
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, I'd just like to see a few more function description comments, perhaps reduce the body size with a little more function extraction, and I was wondering if it might be preferable to create a new file to put some of the helper funcs in? This file is getting very large. Alternative might be to put the whole lot in repositories_create_file file, as it doesn't have to be a file per toolset. WDYT?
…to push_files-allow-empty-repo
|
- Ksenia created a PR to improve the push_files tool by adding auto-init
and branch creation.
- Copilot and Sam offered reviews, suggesting fixes and
-
-
-
- more function extraction.
On Mon, Jan 5, 2026, 3:40 AM Ksenia Bobrova ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pkg/github/repositories.go
<#1676 (comment)>
:
> + return nil, nil, fmt.Errorf("failed to get repository: %w", err)
+ }
+ if resp != nil && resp.Body != nil {
+ defer func() { _ = resp.Body.Close() }()
+ }
+
+ defaultBranch := repository.GetDefaultBranch()
+
+ fileOpts := &github.RepositoryContentFileOptions{
+ Message: github.Ptr("Initial commit"),
+ Content: []byte(""),
+ Branch: github.Ptr(defaultBranch),
+ }
+
+ // Create an initial empty commit to create the default branch
+ createResp, resp, err := client.Repositories.CreateFile(ctx, owner, repo, "README.md", fileOpts)
yeah, I've been trying different options but none of them worked. It
appears that we need an empty file.
—
Reply to this email directly, view it on GitHub
<#1676 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/B2QS3PQ53MQRCMK4OVAYU5L4FJESRAVCNFSM6AAAAACPZUHXEWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTMMRWGUYTKMRWGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
10ee826b440b68c3e19f004d330116a9173e2f96052afa3a98e67f6af948c676 gh_2.83.2_linux_386.deb
3696820ea64ed8b666856eba60345c7c0629fed30f12adc130ee53b81f669c60 gh_2.83.2_linux_386.rpm
72934bf79559b61d1e810a838025301f1f5fed674108b198991da5b383ff9cfa gh_2.83.2_linux_386.tar.gz
7cc4ec4aa80b798a78a1db35d9286495aecb41106fae245a3d7436a68692775f gh_2.83.2_linux_amd64.deb
cca0a1cfdc78bdc2af12d0893da8f0d4e4813763e1eed7a0612295779ec7f53c gh_2.83.2_linux_amd64.rpm
ca6e7641214fbd0e21429cec4b64a7ba626fd946d8f9d6d191467545b092015e gh_2.83.2_linux_amd64.tar.gz
865af610361e3fd9ef224862548726d36953382098fecfc098d3bae4aa724fb7 gh_2.83.2_linux_arm64.deb
21627a659dbc7f3570443fa49bd7a7c75520e76c297f63cc37195e76779877e2 gh_2.83.2_linux_arm64.rpm
b1a0c0a0fcf18524e36996caddc92a062355ed014defc836203fe20fba75a38e gh_2.83.2_linux_arm64.tar.gz
67a89a00574336ff880fc1187ba1d63fff6711f92933560745530ac6f80dca70 gh_2.83.2_linux_armv6.deb
a16bed7ba16bc2e91707dfcce6cdcc1b1b36224d6447ffc54415d46487150536 gh_2.83.2_linux_armv6.rpm
c706d39f24cc79be47ef39eaa986860ffa2e841289fa5b63ff5e24fccf843474 gh_2.83.2_linux_armv6.tar.gz
6f1712519ccc768946791dc97da407bf188582345b73fef3d604d050ebf6f614 gh_2.83.2_macOS_amd64.zip
ba3e0396ebbc8da17256144ddda503e4e79c8b502166335569f8390d6b75fa8d gh_2.83.2_macOS_arm64.zip
e26ff0bd556a60867ad2637c9e3b44d87223c2ef8f701a473cb59314ed7d677f gh_2.83.2_macOS_universal.pkg
7d0c7ae7aec849de43d9a241edb474095ad0c6af2e51fe881c943f2199bad357 gh_2.83.2_windows_386.msi
b5310c1c12a6cbcd72188763c76ea50f5a746efe52e5ab95dee7a770dbbc3ca1 gh_2.83.2_windows_386.zip
4d296c785afa586f75b505a6b7b875f17f727a97eb85589771d8b18e6ae541c8 gh_2.83.2_windows_amd64.msi
b95bf2d953e3bf497bb2c0aed97ffcc5ed8471b80f0920d663a92a6111f05135 gh_2.83.2_windows_amd64.zip
55f851028bdad0816cbf3ea34562413fee35017db2127a3b9597ee74b98fd463 gh_2.83.2_windows_arm64.msi
a341bf9e1074a1586c2ce3e0e46685c1722b4c99a4699b34a906e3a47e3885e5 gh_2.83.2_windows_arm64.zip
|
|
@SamMorrowDrums extracted helpers to a separate file |
SamMorrowDrums
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @almaleksia 🤞 it makes a big dent in errors. It is such a common issue. Even regular folks get confused by unitialized repos sometimes.
Summary
This PR aims to significantly reduce failure rate for push_files tool.
Why
push_files tool fails too often due to rigid assumptions that both ref that files are pushed to exists and repo is not empty. However, it is very often not the case and we shouldn't fail on such common cases.
MCP impact
Prompts tested (tool changes only)
Security / limits
Lint & tests
./script/lint./script/testDocs