forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple way to rename branch like gh (go-gitea#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>
- Loading branch information
1 parent
c16eae1
commit 38e73bd
Showing
14 changed files
with
357 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- | ||
id: 1 | ||
repo_id: 1 | ||
from: dev | ||
to: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 migrations | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func addRenamedBranchTable(x *xorm.Engine) error { | ||
type RenamedBranch struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"INDEX NOT NULL"` | ||
From string | ||
To string | ||
CreatedUnix int64 `xorm:"created"` | ||
} | ||
return x.Sync2(new(RenamedBranch)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.