Use case-insensitive matching for Git error "Not a valid object name"#36728
Conversation
|
Thank you very much. I will try to extract the logic into a shared function to improve maintainability. |
|
I'm not sure the refactor is warrented. Previous code was easy to read with two |
|
I investigated for more git errors that are matched case-sensitively in the code base and found these:
Maybe we should fix them all here, or in another PR. |
No
They are different cases. Using magic string is fragile |
Do you agree they need fixing?
Could be made constants |
But upstream doesn't convert them to lower case lore.kernel.org/git/pull.2052.git.1771836302101.gitgitgadget@gmail.com |
Not yet, but I assume git authors will want to eventually unify all their messages to lowercase and we could be pre-prepared for when it happens. |
By the way, the design can be like this, just FYI: Or always do "fold" comparing, only keep Another idea is to introduce enough functions for different error types, and sometimes we need to parse the git's stderr. However, I don't think these ideas are mature enough, haven't spend time on it. |
|
Yeah anything like that is fine, I just don't want gitea to break when git changes casing in more error messages in the future. Matching error message by string is already a bad API, we should make it liberally accept any casing. |
Yes, that's why I made many changes to the "git" packages. https://github.com/go-gitea/gitea/pulls?q=is%3Apr+git+is%3Aclosed+author%3Awxiaoguang There are also some comments describing the future direction. Till now, the situation is much better than before, but there are still many legacy problems like this: |
|
I wonder if some of these cases could be changed to determine outcome by exit code instead of message. |
|
Answer is in code |
* giteaofficial/main: Fix path resolving (go-gitea#36734) [skip ci] Updated translations via Crowdin Fix track time list permission check (go-gitea#36662) Fix incorrect setting loading order (go-gitea#36735) Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728) feat: Add workflow dependencies visualization (go-gitea#36248)
* main: (24 commits) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714) Fix release draft access check logic (go-gitea#36720) Change image transparency grid to CSS (go-gitea#36711) Avoid opening new tab when downloading actions logs (go-gitea#36740) Add validation constraints for repository creation fields (go-gitea#36671) Fix SVG height calculation in diff viewer (go-gitea#36748) Fix path resolving (go-gitea#36734) [skip ci] Updated translations via Crowdin Fix track time list permission check (go-gitea#36662) Fix incorrect setting loading order (go-gitea#36735) Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728) feat: Add workflow dependencies visualization (go-gitea#36248) Add keyboard shortcuts for repository file and code search (go-gitea#36416) Refactor text utility classes to Tailwind CSS (go-gitea#36703) Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660) Fix force push time-line commit comments of pull request (go-gitea#36653) Fix get release draft permission check (go-gitea#36659) Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256) ... # Conflicts: # web_src/css/base.css # web_src/css/index.css

Fixes #36727
Git is lowercasing the
fatal: Not a valid object nameerror messageto follow its CodingGuidelines. This change makes the string matching
case-insensitive so it works with both the current and future Git versions.
Changes:
strings.ToLower()before checking for the error substringSee: https://lore.kernel.org/git/pull.2052.git.1771836302101.gitgitgadget@gmail.com