Skip to content

Can't PUT again to non-master branch via API #8189

Closed

Description

@dvolozhinok

Gogs version

0.14.2

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 56ec7793e90ce8d94371f8d1d5cfd8fc1d5a0256' \
  --header 'Content-Type: application/json' \
  --data '{
  "branch": "branch1",
  "message": "9",
  "content": "0JfQtNGA0LDRgdGC0LXQlDEyMzUK"
}'

And it gives 201 and works normally.

Then let's PUT again:

curl --request PUT \
  --url https://git.our.org:4443/api/v1/repos/obsidian/users/contents/hello.csv \
  --header 'Authorization: token 56ec7793e90ce8d94371f8d1d5cfd8fc1d5a0256' \
  --header 'Content-Type: application/json' \
  --data '{
  "branch": "branch1",
  "message": "9",
  "content": "0JfQtNGA0LDRgdGC0LXQlDEyMzUK"
}'

It gives code 500 and answer:

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

In logs we have nothing interesting:

2026/02/20 15:00:06 [TRACE] Session ID: 13eb88e882ac620d
2026/02/20 15:00:06 [TRACE] CSRF Token: x443K6qqqC1G3w6PBs5Sc5C5rMQ6MTc3MTU4ODgwNjc4NjY1NTM0Nw
2026/02/20 15:00:06 [ERROR] [...al/route/api/v1/repo/contents.go:205 PutContents()] updating repository file: branch already exists [name: dcloud]
2026/02/20 15:02:25 [TRACE] Session ID: ed15c07425b2c453
2026/02/20 15:02:25 [TRACE] CSRF Token: 7xwlLTqkyt9VPk9sZAokPjItz8o6MTc3MTU4ODk0NTkzODU4MjE2NA
2026/02/20 15:02:26 [TRACE] TriggerTask: obsidian/users@branch1 by "dcloud.ru"
2026/02/20 15:02:26 [TRACE] DeliverHooks [repo_id: 1]
2026/02/20 15:02:26 [TRACE] AddTestPullRequestTask [head_repo_id: 1, head_branch: branch1]: finding pull requests
2026/02/20 15:02:26 [TRACE] AddTestPullRequestTask [base_repo_id: 1, base_branch: branch1]: finding pull requests
2026/02/20 15:03:27 [TRACE] Session ID: 86dff5b578371c94
2026/02/20 15:03:27 [TRACE] CSRF Token: PPVFgc0WP1meDKMCV9LigpAwpaw6MTc3MTU4OTAwNzU0OTY1NDE3OQ
2026/02/20 15:03:27 [ERROR] [...al/route/api/v1/repo/contents.go:205 PutContents()] updating repository file: branch already exists [name: branch1]

To reproduce

  1. Use the same distro;
  2. Add user and group for gogs;
  3. Add systemd service;
  4. Run it;
  5. Add 2 users;
  6. Create repo from 1st user;
  7. Add permissions to write for the 2nd user;
  8. Add marker API key for non-author of the repo for the 2nd user;
  9. Perform the same requests.

Expected behavior

Second PUT without errors and with code 201.

Additional context

@unknwon Good day, I've tagged you as we previously agreed in issue #8181

Code of Conduct

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

Activity

  1. added
    💊 bug
    on Feb 20, 2026
  2. changed the title [-]Can't post to non-master branch via API[/-] [+]Can't PUT again to non-master branch via API[/+] on Feb 20, 2026
  3. unknwon commented on Feb 20, 2026

    @unknwon
    Member

    Hey @dvolozhinok, thanks for the report! Just quick check, it was wrong before 0.14 for you? (if you don't know it's OK just wanna collect a data point).

  4. dvolozhinok commented on Feb 20, 2026

    @dvolozhinok
    Author

    Hey @dvolozhinok, thanks for the report! Just quick check, it was wrong before 0.14 for you? (if you don't know it's OK just wanna collect a data point).

    I don't know. I've started using this API from version 0.14.1
    I've launched another Gogs instance with separate user and sqlite3 as DB for the separate project which is in dev right now.

    For existing project we use not the latest Gogs, SSH-based pushes only and never update it. We follow the electricians' principle "It works — don't touch it!"

  5. unknwon commented on Feb 20, 2026

    @unknwon
    Member

    Haha, makes the perfect sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    💊 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions