Skip to content

Commit 9ea7ab7

Browse files
committed
Remove wikipath method
1 parent f32dd3c commit 9ea7ab7

File tree

6 files changed

+73
-71
lines changed

6 files changed

+73
-71
lines changed

models/repo/wiki.go

Lines changed: 0 additions & 6 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"
@@ -85,8 +84,3 @@ func RelativeWikiPath(ownerName, repoName string) string {
8584
func (repo *Repository) WikiStorageRepo() StorageRepo {
8685
return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
8786
}
88-
89-
// WikiPath returns wiki data path for given repository.
90-
func (repo *Repository) WikiPath() string {
91-
return filepath.Join(user_model.UserPath(repo.OwnerName), strings.ToLower(repo.Name)+".wiki.git")
92-
}

models/repo/wiki_test.go

Lines changed: 0 additions & 9 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
)
@@ -22,10 +20,3 @@ func TestRepository_WikiCloneLink(t *testing.T) {
2220
assert.Equal(t, "ssh://[email protected]:3000/user2/repo1.wiki.git", cloneLink.SSH)
2321
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
2422
}
25-
26-
func TestRepository_WikiPath(t *testing.T) {
27-
assert.NoError(t, unittest.PrepareTestDatabase())
28-
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
29-
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
30-
assert.Equal(t, expected, repo.WikiPath())
31-
}

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").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
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").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
49+
signingKey, _, _ := gitcmd.NewCommand("config", "--get", "user.signingkey").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
50+
signingName, _, _ := gitcmd.NewCommand("config", "--get", "user.name").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
51+
signingEmail, _, _ := gitcmd.NewCommand("config", "--get", "user.email").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
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/signing.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 GetSigningKey(ctx context.Context, repo Repository) (*git.SigningKey, *git.Signature) {
13+
return git.GetSigningKey(ctx, repoPath(repo))
14+
}

routers/web/repo/setting/setting.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"code.gitea.io/gitea/modules/validation"
3030
"code.gitea.io/gitea/modules/web"
3131
actions_service "code.gitea.io/gitea/services/actions"
32-
asymkey_service "code.gitea.io/gitea/services/asymkey"
3332
"code.gitea.io/gitea/services/context"
3433
"code.gitea.io/gitea/services/forms"
3534
"code.gitea.io/gitea/services/migrations"
@@ -62,7 +61,7 @@ func SettingsCtxData(ctx *context.Context) {
6261
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
6362
ctx.Data["CanConvertFork"] = ctx.Repo.Repository.IsFork && ctx.Doer.CanCreateRepoIn(ctx.Repo.Repository.Owner)
6463

65-
signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath())
64+
signing, _ := gitrepo.GetSigningKey(ctx, ctx.Repo.Repository)
6665
ctx.Data["SigningKeyAvailable"] = signing != nil
6766
ctx.Data["SigningSettings"] = setting.Repository.Signing
6867
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
@@ -105,7 +104,7 @@ func SettingsPost(ctx *context.Context) {
105104
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
106105
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
107106

108-
signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath())
107+
signing, _ := gitrepo.GetSigningKey(ctx, ctx.Repo.Repository)
109108
ctx.Data["SigningKeyAvailable"] = signing != nil
110109
ctx.Data["SigningSettings"] = setting.Repository.Signing
111110
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled

services/asymkey/sign.go

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
repo_model "code.gitea.io/gitea/models/repo"
1818
user_model "code.gitea.io/gitea/models/user"
1919
"code.gitea.io/gitea/modules/git"
20-
"code.gitea.io/gitea/modules/git/gitcmd"
2120
"code.gitea.io/gitea/modules/gitrepo"
2221
"code.gitea.io/gitea/modules/log"
2322
"code.gitea.io/gitea/modules/process"
@@ -109,54 +108,9 @@ func IsErrWontSign(err error) bool {
109108
return ok
110109
}
111110

112-
// SigningKey returns the KeyID and git Signature for the repo
113-
func SigningKey(ctx context.Context, repoPath string) (*git.SigningKey, *git.Signature) {
114-
if setting.Repository.Signing.SigningKey == "none" {
115-
return nil, nil
116-
}
117-
118-
if setting.Repository.Signing.SigningKey == "default" || setting.Repository.Signing.SigningKey == "" {
119-
// Can ignore the error here as it means that commit.gpgsign is not set
120-
value, _, _ := gitcmd.NewCommand("config", "--get", "commit.gpgsign").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
121-
sign, valid := git.ParseBool(strings.TrimSpace(value))
122-
if !sign || !valid {
123-
return nil, nil
124-
}
125-
126-
format, _, _ := gitcmd.NewCommand("config", "--default", git.SigningKeyFormatOpenPGP, "--get", "gpg.format").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
127-
signingKey, _, _ := gitcmd.NewCommand("config", "--get", "user.signingkey").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
128-
signingName, _, _ := gitcmd.NewCommand("config", "--get", "user.name").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
129-
signingEmail, _, _ := gitcmd.NewCommand("config", "--get", "user.email").RunStdString(ctx, &gitcmd.RunOpts{Dir: repoPath})
130-
131-
if strings.TrimSpace(signingKey) == "" {
132-
return nil, nil
133-
}
134-
135-
return &git.SigningKey{
136-
KeyID: strings.TrimSpace(signingKey),
137-
Format: strings.TrimSpace(format),
138-
}, &git.Signature{
139-
Name: strings.TrimSpace(signingName),
140-
Email: strings.TrimSpace(signingEmail),
141-
}
142-
}
143-
144-
if setting.Repository.Signing.SigningKey == "" {
145-
return nil, nil
146-
}
147-
148-
return &git.SigningKey{
149-
KeyID: setting.Repository.Signing.SigningKey,
150-
Format: setting.Repository.Signing.SigningFormat,
151-
}, &git.Signature{
152-
Name: setting.Repository.Signing.SigningName,
153-
Email: setting.Repository.Signing.SigningEmail,
154-
}
155-
}
156-
157111
// PublicSigningKey gets the public signing key within a provided repository directory
158112
func PublicSigningKey(ctx context.Context, repoPath string) (content, format string, err error) {
159-
signingKey, _ := SigningKey(ctx, repoPath)
113+
signingKey, _ := git.GetSigningKey(ctx, repoPath)
160114
if signingKey == nil {
161115
return "", "", nil
162116
}
@@ -181,7 +135,7 @@ func PublicSigningKey(ctx context.Context, repoPath string) (content, format str
181135
// SignInitialCommit determines if we should sign the initial commit to this repository
182136
func SignInitialCommit(ctx context.Context, repoPath string, u *user_model.User) (bool, *git.SigningKey, *git.Signature, error) {
183137
rules := signingModeFromStrings(setting.Repository.Signing.InitialCommit)
184-
signingKey, sig := SigningKey(ctx, repoPath)
138+
signingKey, sig := git.GetSigningKey(ctx, repoPath)
185139
if signingKey == nil {
186140
return false, nil, nil, &ErrWontSign{noKey}
187141
}
@@ -216,9 +170,8 @@ Loop:
216170

217171
// SignWikiCommit determines if we should sign the commits to this repository wiki
218172
func SignWikiCommit(ctx context.Context, repo *repo_model.Repository, u *user_model.User) (bool, *git.SigningKey, *git.Signature, error) {
219-
repoWikiPath := repo.WikiPath()
220173
rules := signingModeFromStrings(setting.Repository.Signing.Wiki)
221-
signingKey, sig := SigningKey(ctx, repoWikiPath)
174+
signingKey, sig := gitrepo.GetSigningKey(ctx, repo.WikiStorageRepo())
222175
if signingKey == nil {
223176
return false, nil, nil, &ErrWontSign{noKey}
224177
}
@@ -271,7 +224,7 @@ Loop:
271224
// SignCRUDAction determines if we should sign a CRUD commit to this repository
272225
func SignCRUDAction(ctx context.Context, repoPath string, u *user_model.User, tmpBasePath, parentCommit string) (bool, *git.SigningKey, *git.Signature, error) {
273226
rules := signingModeFromStrings(setting.Repository.Signing.CRUDActions)
274-
signingKey, sig := SigningKey(ctx, repoPath)
227+
signingKey, sig := git.GetSigningKey(ctx, repoPath)
275228
if signingKey == nil {
276229
return false, nil, nil, &ErrWontSign{noKey}
277230
}
@@ -335,7 +288,7 @@ func SignMerge(ctx context.Context, pr *issues_model.PullRequest, u *user_model.
335288
}
336289
repo := pr.BaseRepo
337290

338-
signingKey, signer := SigningKey(ctx, repo.RepoPath())
291+
signingKey, signer := gitrepo.GetSigningKey(ctx, repo)
339292
if signingKey == nil {
340293
return false, nil, nil, &ErrWontSign{noKey}
341294
}

0 commit comments

Comments
 (0)