Merge pull request '[gitea] week 2024-23-v7.0 cherry pick (release/v1.22 -> v7.0/forgejo)' (#4004) from earl-warren/wcp/2024-23-v7.0 into v7.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4004 Reviewed-by: Victoria <efertone@noreply.codeberg.org>
This commit is contained in:
commit
e17e330712
6 changed files with 60 additions and 11 deletions
|
@ -92,17 +92,13 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
|
||||||
|
|
||||||
func (opts FindBranchOptions) ToOrders() string {
|
func (opts FindBranchOptions) ToOrders() string {
|
||||||
orderBy := opts.OrderBy
|
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 == "" {
|
if orderBy == "" {
|
||||||
// the commit_time might be the same, so add the "name" to make sure the order is stable
|
// 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
|
return orderBy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ func addObjectFormatNameToRepository(x *xorm.Engine) error {
|
||||||
|
|
||||||
// Here to catch weird edge-cases where column constraints above are
|
// Here to catch weird edge-cases where column constraints above are
|
||||||
// not applied by the DB backend
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
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 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
|
// if database have branches but not this branch, it means this is a new branch
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="issue-card-icon">
|
<div class="issue-card-icon">
|
||||||
{{template "shared/issueicon" .}}
|
{{template "shared/issueicon" .}}
|
||||||
</div>
|
</div>
|
||||||
<a class="issue-card-title muted issue-title" href="{{.Link}}">{{.Title | RenderEmoji ctx | RenderCodeBlock}}</a>
|
<a class="issue-card-title muted issue-title tw-break-anywhere" href="{{.Link}}">{{.Title | RenderEmoji ctx | RenderCodeBlock}}</a>
|
||||||
{{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}}
|
{{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}}
|
||||||
<a role="button" class="issue-card-unpin muted tw-flex tw-items-center" data-tooltip-content={{ctx.Locale.Tr "repo.issues.unpin_issue"}} data-issue-id="{{.ID}}" data-unpin-url="{{$.Page.Link}}/unpin/{{.Index}}">
|
<a role="button" class="issue-card-unpin muted tw-flex tw-items-center" data-tooltip-content={{ctx.Locale.Tr "repo.issues.unpin_issue"}} data-issue-id="{{.ID}}" data-unpin-url="{{$.Page.Link}}/unpin/{{.Index}}">
|
||||||
{{svg "octicon-x" 16}}
|
{{svg "octicon-x" 16}}
|
||||||
|
|
|
@ -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) {
|
func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
|
@ -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) {
|
t.Run("Push branches one by one", func(t *testing.T) {
|
||||||
runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) {
|
runTestGitPush(t, u, objectFormat, func(t *testing.T, gitPath string) (pushed, deleted []string) {
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
|
Loading…
Reference in a new issue