aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2021-10-09 01:03:04 +0800
committerGitHub <noreply@github.com>2021-10-08 19:03:04 +0200
commitbb393596689ee7c33ecb041806ae2c9e8dc5dfab (patch)
treec6b71f73e53d5d5c1bb1da9e47e917f23538cd3f /integrations
parent56d79301b9f212e7801cbced1475238cc61c0748 (diff)
downloadgitea-bb393596689ee7c33ecb041806ae2c9e8dc5dfab.tar.gz
gitea-bb393596689ee7c33ecb041806ae2c9e8dc5dfab.zip
Add a simple way to rename branch like gh (#15870)
- Update default branch if needed - Update protected branch if needed - Update all not merged pull request base branch name - Rename git branch - Record this rename work and auto redirect for old branch on ui Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/rename_branch_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/integrations/rename_branch_test.go b/integrations/rename_branch_test.go
new file mode 100644
index 0000000000..90c1f4d15f
--- /dev/null
+++ b/integrations/rename_branch_test.go
@@ -0,0 +1,44 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package integrations
+
+import (
+ "net/http"
+ "testing"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRenameBranch(t *testing.T) {
+ // 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)
+ session.MakeRequest(t, req, http.StatusFound)
+
+ // 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)
+ resp = session.MakeRequest(t, req, http.StatusFound)
+ location := resp.HeaderMap.Get("Location")
+ assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
+
+ // check db
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ assert.Equal(t, "main", repo1.DefaultBranch)
+}