Skip to content

Can't use API to PUT file the second time #8181

@dvolozhinok

Description

@dvolozhinok

Gogs version

0.14.1

Git version

  • Server: 2.39.3
  • Client: N\A (I believe 2.39.3 since I'm using the API)

Operating system

Oracle Linux Server 8.8

Database

sqlite3

Describe the bug

Using HTTPie GUI to make this request:

curl --request PUT \
  --url https://git.our.org:4443/api/v1/repos/obsidian/users/contents/hello.csv \
  --header 'Authorization: token 622aaf6099f5d9642a70f13b692c46e0fb2985de' \
  --header 'Content-Type: application/json' \
  --data '{
  "branch": "master",
  "message": "4",
  "content": "SGVsbG8K"
}'

It gives HTTP code 500 and the reply:

{
  "message": "Something went wrong, please check the server logs for more information.",
  "url": "https://github.com/gogs/docs-api"
}

In logs:

2026/02/16 14:30:35 [TRACE] Session ID: 49062c37948bd910
2026/02/16 14:30:35 [TRACE] CSRF Token: 622aaf6099f5d9642a70f13b692c46e0fb2985de
2026/02/16 14:30:35 [ERROR] [...al/route/api/v1/repo/contents.go:205 PutContents()] updating repository file: discard local repo branch[master] changes: reset [revision: origin/master]: exit status 128 - fatal: option '--end-of-options' must come before non-option arguments

If uptime of the service is low and the branch is new, not existing one it works and gives positive reply. And I can then open file through the web interface.
The second PUT request fails.
Any PUT request to master fails.

To reproduce

  1. Use the same distro;
  2. Add user for gogs + group;
  3. Add systemd service;
  4. Run it.

Expected behavior

Normally working API to PUT.

Additional context

Daemon file

[Unit]
Description=Gogs git remote daemon NEW
After=syslog.target
After=network.target

[Service]
LimitMEMLOCK=infinity
LimitNOFILE=131072
Type=simple
User=gogs_new
Group=gogs_new
WorkingDirectory=/opt/gogs_new
ExecStart=/opt/gogs_new/gogs web -p 4000
Restart=always
RestartSec=5s
Environment=USER=gogs_new HOME=/opt/gogs_new

[Install]
WantedBy=multi-user.target

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

💊 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions