2021-10-08 13:03:04 -04:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-10-08 13:03:04 -04:00
|
|
|
|
2022-09-02 15:18:23 -04:00
|
|
|
package integration
|
2021-10-08 13:03:04 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2023-06-29 06:03:20 -04:00
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 03:53:21 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2023-06-29 06:03:20 -04:00
|
|
|
"code.gitea.io/gitea/tests"
|
2021-11-17 07:34:35 -05:00
|
|
|
|
2021-10-08 13:03:04 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRenameBranch(t *testing.T) {
|
2023-06-29 06:03:20 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: 1, Name: "master"})
|
|
|
|
|
2021-10-08 13:03:04 -04:00
|
|
|
// get branch setting page
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/settings/branches")
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
postData := map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"from": "master",
|
|
|
|
"to": "main",
|
|
|
|
}
|
|
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData)
|
2022-03-23 00:54:07 -04:00
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2021-10-08 13:03:04 -04:00
|
|
|
|
|
|
|
// check new branch link
|
|
|
|
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData)
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
// check old branch link
|
|
|
|
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
|
2022-03-23 00:54:07 -04:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
2022-12-02 17:06:23 -05:00
|
|
|
location := resp.Header().Get("Location")
|
2021-10-08 13:03:04 -04:00
|
|
|
assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
|
|
|
|
|
|
|
|
// check db
|
2022-08-15 22:22:25 -04:00
|
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2021-10-08 13:03:04 -04:00
|
|
|
assert.Equal(t, "main", repo1.DefaultBranch)
|
|
|
|
}
|