-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix PATCH /repos/{owner}/{repo} panic #14637
Fix PATCH /repos/{owner}/{repo} panic #14637
Conversation
Using the `PATCH /repos/{owner}/{repo}` endpoint and attempting to modify `default_branch` on an empty repository will cause a panic. This commit adds a check for a nil pointer before attempting to dereference it.
I think the problem is that the ctx.Repo.GitRepo should never not be nil. It's likely that we need to load the gitrepo directly ourselves. If we merged this pr as it stands git's idea of the default branch won't be updated. |
We can take a look at the code responsible for injecting |
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.
As this stands this will not work.
a other option would be to just check |
If you change the default branch for a repository you must change it in git too. Therefore you must open the repository before changing the default branch. Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath on an empty repo you can NOT open a git repo! |
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.
blocking per comment
Why don't you try... |
You can very definitely open a git repository on an empty repository. The git repository is there and the set default branch etc will work fine. In fact you need to set the default branch on the empty repo otherwise the default branch will not work correctly. Now the change where you now test if the branch exists is an issue. If the repo is empty we should allow any branch to be set as the default branch. If the repo is not empty we will need to ensure that the branch existing I suspect. |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Sorry, to be clear, the repository isn't just empty, but it has not yet even been initialized. Should it be possible to open an uninitialized git repository? |
@zeripath your patch works, but it just looks wrong .. |
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 works ...
When attempting to modify the
"default_branch"
field of an empty repository through thePATCH /repos/{owner}/{repo}
endpoint, you get a runtime error due to a nil pointer dereference:This PR adds a check to see if the pointer is nil before attempting to dereference.