Skip to content

Commit 4096abc

Browse files
authored
Merge branch 'main' into quick-approval-action-btn
2 parents 6cb1cf3 + 2d36a0c commit 4096abc

File tree

34 files changed

+299
-237
lines changed

34 files changed

+299
-237
lines changed

models/issues/issue_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func applySubscribedCondition(sess *xorm.Session, subscriberID int64) {
476476
),
477477
builder.Eq{"issue.poster_id": subscriberID},
478478
builder.In("issue.repo_id", builder.
479-
Select("id").
479+
Select("repo_id").
480480
From("watch").
481481
Where(builder.And(builder.Eq{"user_id": subscriberID},
482482
builder.In("mode", repo_model.WatchModeNormal, repo_model.WatchModeAuto))),

models/issues/issue_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ func TestIssues(t *testing.T) {
197197
},
198198
[]int64{2},
199199
},
200+
{
201+
issues_model.IssuesOptions{
202+
SubscriberID: 11,
203+
},
204+
[]int64{11, 5, 9, 8, 3, 2, 1},
205+
},
200206
} {
201207
issues, err := issues_model.Issues(t.Context(), &test.Opts)
202208
assert.NoError(t, err)

models/repo/repo.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ func RelativePath(ownerName, repoName string) string {
229229
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".git"
230230
}
231231

232-
func RelativeWikiPath(ownerName, repoName string) string {
233-
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".wiki.git"
234-
}
235-
236232
// RelativePath should be an unix style path like username/reponame.git
237233
func (repo *Repository) RelativePath() string {
238234
return RelativePath(repo.OwnerName, repo.Name)
@@ -245,12 +241,6 @@ func (sr StorageRepo) RelativePath() string {
245241
return string(sr)
246242
}
247243

248-
// WikiStorageRepo returns the storage repo for the wiki
249-
// The wiki repository should have the same object format as the code repository
250-
func (repo *Repository) WikiStorageRepo() StorageRepo {
251-
return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
252-
}
253-
254244
// SanitizedOriginalURL returns a sanitized OriginalURL
255245
func (repo *Repository) SanitizedOriginalURL() string {
256246
if repo.OriginalURL == "" {

models/repo/wiki.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package repo
77
import (
88
"context"
99
"fmt"
10-
"path/filepath"
1110
"strings"
1211

1312
user_model "code.gitea.io/gitea/models/user"
@@ -76,12 +75,12 @@ func (repo *Repository) WikiCloneLink(ctx context.Context, doer *user_model.User
7675
return repo.cloneLink(ctx, doer, repo.Name+".wiki")
7776
}
7877

79-
// WikiPath returns wiki data path by given user and repository name.
80-
func WikiPath(userName, repoName string) string {
81-
return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".wiki.git")
78+
func RelativeWikiPath(ownerName, repoName string) string {
79+
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".wiki.git"
8280
}
8381

84-
// WikiPath returns wiki data path for given repository.
85-
func (repo *Repository) WikiPath() string {
86-
return WikiPath(repo.OwnerName, repo.Name)
82+
// WikiStorageRepo returns the storage repo for the wiki
83+
// The wiki repository should have the same object format as the code repository
84+
func (repo *Repository) WikiStorageRepo() StorageRepo {
85+
return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
8786
}

models/repo/wiki_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
package repo_test
55

66
import (
7-
"path/filepath"
87
"testing"
98

109
repo_model "code.gitea.io/gitea/models/repo"
1110
"code.gitea.io/gitea/models/unittest"
12-
"code.gitea.io/gitea/modules/setting"
1311

1412
"github.com/stretchr/testify/assert"
1513
)
@@ -23,15 +21,10 @@ func TestRepository_WikiCloneLink(t *testing.T) {
2321
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
2422
}
2523

26-
func TestWikiPath(t *testing.T) {
24+
func TestRepository_RelativeWikiPath(t *testing.T) {
2725
assert.NoError(t, unittest.PrepareTestDatabase())
28-
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
29-
assert.Equal(t, expected, repo_model.WikiPath("user2", "repo1"))
30-
}
3126

32-
func TestRepository_WikiPath(t *testing.T) {
33-
assert.NoError(t, unittest.PrepareTestDatabase())
3427
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
35-
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
36-
assert.Equal(t, expected, repo.WikiPath())
28+
assert.Equal(t, "user2/repo1.wiki.git", repo_model.RelativeWikiPath(repo.OwnerName, repo.Name))
29+
assert.Equal(t, "user2/repo1.wiki.git", repo.WikiStorageRepo().RelativePath())
3730
}

modules/git/key.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
package git
55

6-
import "code.gitea.io/gitea/modules/setting"
6+
import (
7+
"context"
8+
"strings"
9+
10+
"code.gitea.io/gitea/modules/git/gitcmd"
11+
"code.gitea.io/gitea/modules/setting"
12+
)
713

814
// Based on https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
915
const (
@@ -24,3 +30,48 @@ func (s *SigningKey) String() string {
2430
setting.PanicInDevOrTesting("don't call SigningKey.String() - it exposes the KeyID which might be a local file path")
2531
return "SigningKey:" + s.Format
2632
}
33+
34+
// GetSigningKey returns the KeyID and git Signature for the repo
35+
func GetSigningKey(ctx context.Context, repoPath string) (*SigningKey, *Signature) {
36+
if setting.Repository.Signing.SigningKey == "none" {
37+
return nil, nil
38+
}
39+
40+
if setting.Repository.Signing.SigningKey == "default" || setting.Repository.Signing.SigningKey == "" {
41+
// Can ignore the error here as it means that commit.gpgsign is not set
42+
value, _, _ := gitcmd.NewCommand("config", "--get", "commit.gpgsign").WithDir(repoPath).RunStdString(ctx)
43+
sign, valid := ParseBool(strings.TrimSpace(value))
44+
if !sign || !valid {
45+
return nil, nil
46+
}
47+
48+
format, _, _ := gitcmd.NewCommand("config", "--default", SigningKeyFormatOpenPGP, "--get", "gpg.format").WithDir(repoPath).RunStdString(ctx)
49+
signingKey, _, _ := gitcmd.NewCommand("config", "--get", "user.signingkey").WithDir(repoPath).RunStdString(ctx)
50+
signingName, _, _ := gitcmd.NewCommand("config", "--get", "user.name").WithDir(repoPath).RunStdString(ctx)
51+
signingEmail, _, _ := gitcmd.NewCommand("config", "--get", "user.email").WithDir(repoPath).RunStdString(ctx)
52+
53+
if strings.TrimSpace(signingKey) == "" {
54+
return nil, nil
55+
}
56+
57+
return &SigningKey{
58+
KeyID: strings.TrimSpace(signingKey),
59+
Format: strings.TrimSpace(format),
60+
}, &Signature{
61+
Name: strings.TrimSpace(signingName),
62+
Email: strings.TrimSpace(signingEmail),
63+
}
64+
}
65+
66+
if setting.Repository.Signing.SigningKey == "" {
67+
return nil, nil
68+
}
69+
70+
return &SigningKey{
71+
KeyID: setting.Repository.Signing.SigningKey,
72+
Format: setting.Repository.Signing.SigningFormat,
73+
}, &Signature{
74+
Name: setting.Repository.Signing.SigningName,
75+
Email: setting.Repository.Signing.SigningEmail,
76+
}
77+
}

modules/gitrepo/clone.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package gitrepo
5+
6+
import (
7+
"context"
8+
9+
"code.gitea.io/gitea/modules/git"
10+
)
11+
12+
// CloneExternalRepo clones an external repository to the managed repository.
13+
func CloneExternalRepo(ctx context.Context, fromRemoteURL string, toRepo Repository, opts git.CloneRepoOptions) error {
14+
return git.Clone(ctx, fromRemoteURL, repoPath(toRepo), opts)
15+
}
16+
17+
// CloneRepoToLocal clones a managed repository to a local path.
18+
func CloneRepoToLocal(ctx context.Context, fromRepo Repository, toLocalPath string, opts git.CloneRepoOptions) error {
19+
return git.Clone(ctx, repoPath(fromRepo), toLocalPath, opts)
20+
}

modules/gitrepo/commitgraph.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package gitrepo
5+
6+
import (
7+
"context"
8+
9+
"code.gitea.io/gitea/modules/git"
10+
)
11+
12+
func WriteCommitGraph(ctx context.Context, repo Repository) error {
13+
return git.WriteCommitGraph(ctx, repoPath(repo))
14+
}

modules/gitrepo/gitrepo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import (
77
"context"
88
"fmt"
99
"io"
10+
"io/fs"
11+
"os"
1012
"path/filepath"
1113

1214
"code.gitea.io/gitea/modules/git"
15+
"code.gitea.io/gitea/modules/git/gitcmd"
1316
"code.gitea.io/gitea/modules/reqctx"
1417
"code.gitea.io/gitea/modules/setting"
1518
"code.gitea.io/gitea/modules/util"
@@ -86,3 +89,12 @@ func RenameRepository(ctx context.Context, repo, newRepo Repository) error {
8689
func InitRepository(ctx context.Context, repo Repository, objectFormatName string) error {
8790
return git.InitRepository(ctx, repoPath(repo), true, objectFormatName)
8891
}
92+
93+
func UpdateServerInfo(ctx context.Context, repo Repository) error {
94+
_, _, err := RunCmdBytes(ctx, repo, gitcmd.NewCommand("update-server-info"))
95+
return err
96+
}
97+
98+
func GetRepoFS(repo Repository) fs.FS {
99+
return os.DirFS(repoPath(repo))
100+
}

modules/gitrepo/push.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package gitrepo
5+
6+
import (
7+
"context"
8+
9+
"code.gitea.io/gitea/modules/git"
10+
)
11+
12+
func Push(ctx context.Context, repo Repository, opts git.PushOptions) error {
13+
return git.Push(ctx, repoPath(repo), opts)
14+
}

0 commit comments

Comments
 (0)