Skip to content

Commit 27cc5da

Browse files
oliverpoolGiteaBotlunny
committed
fix calReleaseNumCommitsBehind (go-gitea#24148)
Backport go-gitea#24148 `repoCtx.CommitsCount` is not reliably the commit count of the default branch (Repository.GetCommitsCount depends on what is currently displayed). _contributed in the context of @forgejo_ --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent f134229 commit 27cc5da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+934
-21
lines changed

models/db/iterate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
2525
return nil
2626
})
2727
assert.NoError(t, err)
28-
assert.EqualValues(t, 83, repoCnt)
28+
assert.EqualValues(t, 88, repoCnt)
2929

3030
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3131
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/db/list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ func TestFind(t *testing.T) {
3535
var repoUnits []repo_model.RepoUnit
3636
err := db.Find(db.DefaultContext, &opts, &repoUnits)
3737
assert.NoError(t, err)
38-
assert.EqualValues(t, 83, len(repoUnits))
38+
assert.EqualValues(t, 88, len(repoUnits))
3939

4040
cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit))
4141
assert.NoError(t, err)
42-
assert.EqualValues(t, 83, cnt)
42+
assert.EqualValues(t, 88, cnt)
4343

4444
repoUnits = make([]repo_model.RepoUnit, 0, 10)
4545
newCnt, err := db.FindAndCount(db.DefaultContext, &opts, &repoUnits)

models/fixtures/release.yml

+42
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,45 @@
6666
is_prerelease: true
6767
is_tag: false
6868
created_unix: 946684800
69+
70+
- id: 6
71+
repo_id: 57
72+
publisher_id: 2
73+
tag_name: "v1.0"
74+
lower_tag_name: "v1.0"
75+
target: "main"
76+
title: "v1.0"
77+
sha1: "a8a700e8c644c783ba2c6e742bb81bf91e244bff"
78+
num_commits: 3
79+
is_draft: false
80+
is_prerelease: false
81+
is_tag: false
82+
created_unix: 946684801
83+
84+
- id: 7
85+
repo_id: 57
86+
publisher_id: 2
87+
tag_name: "v1.1"
88+
lower_tag_name: "v1.1"
89+
target: "main"
90+
title: "v1.1"
91+
sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6"
92+
num_commits: 5
93+
is_draft: false
94+
is_prerelease: false
95+
is_tag: false
96+
created_unix: 946684802
97+
98+
- id: 8
99+
repo_id: 57
100+
publisher_id: 2
101+
tag_name: "v2.0"
102+
lower_tag_name: "v2.0"
103+
target: "main"
104+
title: "v2.0"
105+
sha1: "7197b56fdc75b453f47c9110938cb46a303579fd"
106+
num_commits: 6
107+
is_draft: false
108+
is_prerelease: false
109+
is_tag: false
110+
created_unix: 946684803

models/fixtures/repo_unit.yml

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# See models/unit/unit.go for the meaning of the type
12
-
23
id: 1
34
repo_id: 1
@@ -569,3 +570,29 @@
569570
type: 3
570571
config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}"
571572
created_unix: 946684810
573+
574+
-
575+
id: 85
576+
repo_id: 57
577+
type: 1
578+
created_unix: 946684810
579+
-
580+
id: 86
581+
repo_id: 57
582+
type: 2
583+
created_unix: 946684810
584+
-
585+
id: 87
586+
repo_id: 57
587+
type: 3
588+
created_unix: 946684810
589+
-
590+
id: 88
591+
repo_id: 57
592+
type: 4
593+
created_unix: 946684810
594+
-
595+
id: 89
596+
repo_id: 57
597+
type: 5
598+
created_unix: 946684810

models/fixtures/repository.yml

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# don't forget to add fixtures in repo_unit.yml
12
-
23
id: 1
34
owner_id: 2
@@ -1634,3 +1635,16 @@
16341635
is_private: true
16351636
num_issues: 1
16361637
status: 0
1638+
1639+
-
1640+
id: 57
1641+
owner_id: 2
1642+
owner_name: user2
1643+
lower_name: repo-release
1644+
name: repo-release
1645+
default_branch: main
1646+
is_empty: false
1647+
is_archived: false
1648+
is_private: false
1649+
status: 0
1650+
num_issues: 0

models/fixtures/user.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
num_followers: 2
6767
num_following: 1
6868
num_stars: 2
69-
num_repos: 11
69+
num_repos: 12
7070
num_teams: 0
7171
num_members: 0
7272
visibility: 0

models/repo/repo_list_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
235235
{
236236
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
237237
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
238-
count: 29,
238+
count: 30,
239239
},
240240
{
241241
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
242242
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
243-
count: 34,
243+
count: 35,
244244
},
245245
{
246246
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
@@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
255255
{
256256
name: "AllPublic/PublicRepositoriesOfOrganization",
257257
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
258-
count: 29,
258+
count: 30,
259259
},
260260
{
261261
name: "AllTemplates",

routers/web/repo/release.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ const (
3535

3636
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
3737
func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model.Release, countCache map[string]int64) error {
38-
// Fast return if release target is same as default branch.
39-
if repoCtx.BranchName == release.Target {
40-
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
41-
return nil
42-
}
43-
4438
// Get count if not exists
4539
if _, ok := countCache[release.Target]; !ok {
46-
if repoCtx.GitRepo.IsBranchExist(release.Target) {
40+
// short-circuit for the default branch
41+
if repoCtx.Repository.DefaultBranch == release.Target || repoCtx.GitRepo.IsBranchExist(release.Target) {
4742
commit, err := repoCtx.GitRepo.GetBranchCommit(release.Target)
4843
if err != nil {
4944
return fmt.Errorf("GetBranchCommit: %w", err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to check the commit log message taken by
4+
# applypatch from an e-mail message.
5+
#
6+
# The hook should exit with non-zero status after issuing an
7+
# appropriate message if it wants to stop the commit. The hook is
8+
# allowed to edit the commit message file.
9+
#
10+
# To enable this hook, rename this file to "applypatch-msg".
11+
12+
. git-sh-setup
13+
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
14+
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
15+
:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to check the commit log message.
4+
# Called by "git commit" with one argument, the name of the file
5+
# that has the commit message. The hook should exit with non-zero
6+
# status after issuing an appropriate message if it wants to stop the
7+
# commit. The hook is allowed to edit the commit message file.
8+
#
9+
# To enable this hook, rename this file to "commit-msg".
10+
11+
# Uncomment the below to add a Signed-off-by line to the message.
12+
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
13+
# hook is more suited to it.
14+
#
15+
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
16+
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
17+
18+
# This example catches duplicate Signed-off-by lines.
19+
20+
test "" = "$(grep '^Signed-off-by: ' "$1" |
21+
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
22+
echo >&2 Duplicate Signed-off-by lines.
23+
exit 1
24+
}

0 commit comments

Comments
 (0)