From d462b6d495a0a07ff445d58eab06a06d93dbd6a6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 29 May 2024 14:43:02 +0800 Subject: [PATCH 1/4] Fix push multiple branches error with tests (#31151) (cherry picked from commit 5c1b550e00e9460078e00c41a32d206b260ef482) Conflicts: tests/integration/git_push_test.go trivial context conflict because of 2ac3dcbd43 test: hook post-receive for sha256 repos (cherry picked from commit 62448bfb931882859388b2fd472cb89428c25323) (cherry picked from commit e8c776c79384c1c0a4d707ce5084b27347703848) --- services/repository/branch.go | 2 +- .../git_helper_for_declarative_test.go | 18 ++++++++++ tests/integration/git_push_test.go | 35 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/services/repository/branch.go b/services/repository/branch.go index a59ad69717..e1a313749f 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -296,7 +296,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames, if _, err := git_model.UpdateBranch(ctx, repoID, pusherID, branchName, commit); err != nil { return fmt.Errorf("git_model.UpdateBranch %d:%s failed: %v", repoID, branchName, err) } - return nil + continue } // if database have branches but not this branch, it means this is a new branch diff --git a/tests/integration/git_helper_for_declarative_test.go b/tests/integration/git_helper_for_declarative_test.go index e9df1d70a4..6fb07e8a01 100644 --- a/tests/integration/git_helper_for_declarative_test.go +++ b/tests/integration/git_helper_for_declarative_test.go @@ -167,6 +167,24 @@ func doGitPushTestRepositoryFail(dstPath string, args ...string) func(*testing.T } } +func doGitAddSomeCommits(dstPath, branch string) func(*testing.T) { + return func(t *testing.T) { + doGitCheckoutBranch(dstPath, branch)(t) + + assert.NoError(t, os.WriteFile(filepath.Join(dstPath, fmt.Sprintf("file-%s.txt", branch)), []byte(fmt.Sprintf("file %s", branch)), 0o644)) + assert.NoError(t, git.AddChanges(dstPath, true)) + signature := git.Signature{ + Email: "test@test.test", + Name: "test", + } + assert.NoError(t, git.CommitChanges(dstPath, git.CommitChangesOptions{ + Committer: &signature, + Author: &signature, + Message: fmt.Sprintf("update %s", branch), + })) + } +} + func doGitCreateBranch(dstPath, branch string) func(*testing.T) { return func(t *testing.T) { t.Helper() diff --git a/tests/integration/git_push_test.go b/tests/integration/git_push_test.go index bbc80cc927..8a9fe81e24 100644 --- a/tests/integration/git_push_test.go +++ b/tests/integration/git_push_test.go @@ -51,6 +51,41 @@ func testGitPush(t *testing.T, u *url.URL) { }) }) + t.Run("Push branches exists", func(t *testing.T) { + runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { + for i := 0; i < 10; i++ { + branchName := fmt.Sprintf("branch-%d", i) + if i < 5 { + pushed = append(pushed, branchName) + } + doGitCreateBranch(gitPath, branchName)(t) + } + // only push master and the first 5 branches + pushed = append(pushed, "master") + args := append([]string{"origin"}, pushed...) + doGitPushTestRepository(gitPath, args...)(t) + + pushed = pushed[:0] + // do some changes for the first 5 branches created above + for i := 0; i < 5; i++ { + branchName := fmt.Sprintf("branch-%d", i) + pushed = append(pushed, branchName) + + doGitAddSomeCommits(gitPath, branchName)(t) + } + + for i := 5; i < 10; i++ { + pushed = append(pushed, fmt.Sprintf("branch-%d", i)) + } + pushed = append(pushed, "master") + + // push all, so that master are not chagned + doGitPushTestRepository(gitPath, "origin", "--all")(t) + + return pushed, deleted + }) + }) + t.Run("Push branches one by one", func(t *testing.T) { runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) { for i := 0; i < 100; i++ { From 4ad7c599e7025eaf5233c914a5d1571ea1de7cea Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 31 May 2024 11:34:05 +0800 Subject: [PATCH 2/4] Fix branch order (#31174) (#31193) Backport #31174 by @lunny Fix #31172 The original order or the default order should not be ignored even if we have an is_deleted order. Co-authored-by: Lunny Xiao (cherry picked from commit c6176ee59f4a25607dcfbc00757121f705101101) --- models/git/branch_list.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index c6fc8ad4b1..9f79d72cde 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -92,17 +92,13 @@ func (opts FindBranchOptions) ToConds() builder.Cond { func (opts FindBranchOptions) ToOrders() string { orderBy := opts.OrderBy - if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the end - if orderBy != "" { - orderBy += ", " - } - orderBy += "is_deleted ASC" - } if orderBy == "" { // the commit_time might be the same, so add the "name" to make sure the order is stable - return "commit_time DESC, name ASC" + orderBy = "commit_time DESC, name ASC" + } + if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the beginning + orderBy = "is_deleted ASC, " + orderBy } - return orderBy } From 4e233dd19095bb521f1d3079be095f6db7d9b2fb Mon Sep 17 00:00:00 2001 From: Giteabot Date: Sun, 2 Jun 2024 15:19:30 +0800 Subject: [PATCH 3/4] Fix the possible migration failure on 286 with postgres 16 (#31209) (#31218) Backport #31209 by @lunny Try to fix #31205 Co-authored-by: Lunny Xiao (cherry picked from commit 68e405cf0b00e475c089d8b94cc076d269ab9bb9) --- models/migrations/v1_22/v286.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go index fbbd87344f..c12c5938a5 100644 --- a/models/migrations/v1_22/v286.go +++ b/models/migrations/v1_22/v286.go @@ -92,7 +92,7 @@ func addObjectFormatNameToRepository(x *xorm.Engine) error { // Here to catch weird edge-cases where column constraints above are // not applied by the DB backend - _, err := x.Exec("UPDATE repository set object_format_name = 'sha1' WHERE object_format_name = '' or object_format_name IS NULL") + _, err := x.Exec("UPDATE `repository` set `object_format_name` = 'sha1' WHERE `object_format_name` = '' or `object_format_name` IS NULL") return err } From e04b490cf6d22af52f402f944ff858b439cddfb4 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Mon, 3 Jun 2024 10:14:15 +0800 Subject: [PATCH 4/4] Fix overflow in issue card (#31203) (#31225) Backport #31203 by @silverwind Before: Screenshot 2024-06-01 at 01 31 26 After: Screenshot 2024-06-01 at 01 31 32 Co-authored-by: silverwind (cherry picked from commit 0328f31fdc9b82efe7110cd2107628c2004e5be4) --- templates/repo/issue/card.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/card.tmpl b/templates/repo/issue/card.tmpl index bb9340bb2e..c734071ef4 100644 --- a/templates/repo/issue/card.tmpl +++ b/templates/repo/issue/card.tmpl @@ -11,7 +11,7 @@
{{template "shared/issueicon" .}}
- {{.Title | RenderEmoji ctx | RenderCodeBlock}} + {{.Title | RenderEmoji ctx | RenderCodeBlock}} {{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}} {{svg "octicon-x" 16}}