Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e5b8200
Use gitrepo.Repository instead of most of wikipath
lunny Sep 2, 2025
02d4f0f
Fix lint
lunny Sep 2, 2025
499f969
Fix bug
lunny Sep 2, 2025
6422004
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 3, 2025
ff860d1
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 5, 2025
5b43cff
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 7, 2025
2b169b9
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 11, 2025
f8fd517
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 17, 2025
f32dd3c
Merge branch 'lunny/remove_wiki_path_ref' of github.com:lunny/gitea i…
lunny Sep 17, 2025
9ea7ab7
Remove wikipath method
lunny Sep 17, 2025
cbfe9ac
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 17, 2025
b7c2f08
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 18, 2025
4396437
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 19, 2025
4d0582a
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 25, 2025
e527a3d
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 26, 2025
214d007
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 26, 2025
51ee9fd
Merge branch 'lunny/remove_wiki_path_ref' of github.com:lunny/gitea i…
lunny Sep 26, 2025
3b625fd
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 29, 2025
06271bd
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Sep 29, 2025
5234986
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Oct 3, 2025
37e210f
Merge branch 'lunny/remove_wiki_path_ref' of github.com:lunny/gitea i…
lunny Oct 3, 2025
d2fc9d2
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Oct 6, 2025
494f563
remove unnecessary code
lunny Oct 7, 2025
156ef6a
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Oct 7, 2025
1096c1e
Merge branch 'lunny/remove_wiki_path_ref' of github.com:lunny/gitea i…
lunny Oct 7, 2025
e0488a0
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Oct 7, 2025
4315055
Merge branch 'main' into lunny/remove_wiki_path_ref
lunny Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ func RelativePath(ownerName, repoName string) string {
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".git"
}

func RelativeWikiPath(ownerName, repoName string) string {
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".wiki.git"
}

// RelativePath should be an unix style path like username/reponame.git
func (repo *Repository) RelativePath() string {
return RelativePath(repo.OwnerName, repo.Name)
Expand All @@ -245,12 +241,6 @@ func (sr StorageRepo) RelativePath() string {
return string(sr)
}

// WikiStorageRepo returns the storage repo for the wiki
// The wiki repository should have the same object format as the code repository
func (repo *Repository) WikiStorageRepo() StorageRepo {
return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
}

// SanitizedOriginalURL returns a sanitized OriginalURL
func (repo *Repository) SanitizedOriginalURL() string {
if repo.OriginalURL == "" {
Expand Down
13 changes: 6 additions & 7 deletions models/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package repo
import (
"context"
"fmt"
"path/filepath"
"strings"

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

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

// WikiPath returns wiki data path for given repository.
func (repo *Repository) WikiPath() string {
return WikiPath(repo.OwnerName, repo.Name)
// WikiStorageRepo returns the storage repo for the wiki
// The wiki repository should have the same object format as the code repository
func (repo *Repository) WikiStorageRepo() StorageRepo {
return StorageRepo(RelativeWikiPath(repo.OwnerName, repo.Name))
}
15 changes: 0 additions & 15 deletions models/repo/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
package repo_test

import (
"path/filepath"
"testing"

repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"

"github.com/stretchr/testify/assert"
)
Expand All @@ -22,16 +20,3 @@ func TestRepository_WikiCloneLink(t *testing.T) {
assert.Equal(t, "ssh://[email protected]:3000/user2/repo1.wiki.git", cloneLink.SSH)
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
}

func TestWikiPath(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, repo_model.WikiPath("user2", "repo1"))
}

func TestRepository_WikiPath(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, repo.WikiPath())
}
53 changes: 52 additions & 1 deletion modules/git/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

package git

import "code.gitea.io/gitea/modules/setting"
import (
"context"
"strings"

"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/setting"
)

// Based on https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
const (
Expand All @@ -24,3 +30,48 @@ func (s *SigningKey) String() string {
setting.PanicInDevOrTesting("don't call SigningKey.String() - it exposes the KeyID which might be a local file path")
return "SigningKey:" + s.Format
}

// GetSigningKey returns the KeyID and git Signature for the repo
func GetSigningKey(ctx context.Context, repoPath string) (*SigningKey, *Signature) {
if setting.Repository.Signing.SigningKey == "none" {
return nil, nil
}

if setting.Repository.Signing.SigningKey == "default" || setting.Repository.Signing.SigningKey == "" {
// Can ignore the error here as it means that commit.gpgsign is not set
value, _, _ := gitcmd.NewCommand("config", "--get", "commit.gpgsign").WithDir(repoPath).RunStdString(ctx)
sign, valid := ParseBool(strings.TrimSpace(value))
if !sign || !valid {
return nil, nil
}

format, _, _ := gitcmd.NewCommand("config", "--default", SigningKeyFormatOpenPGP, "--get", "gpg.format").WithDir(repoPath).RunStdString(ctx)
signingKey, _, _ := gitcmd.NewCommand("config", "--get", "user.signingkey").WithDir(repoPath).RunStdString(ctx)
signingName, _, _ := gitcmd.NewCommand("config", "--get", "user.name").WithDir(repoPath).RunStdString(ctx)
signingEmail, _, _ := gitcmd.NewCommand("config", "--get", "user.email").WithDir(repoPath).RunStdString(ctx)

if strings.TrimSpace(signingKey) == "" {
return nil, nil
}

return &SigningKey{
KeyID: strings.TrimSpace(signingKey),
Format: strings.TrimSpace(format),
}, &Signature{
Name: strings.TrimSpace(signingName),
Email: strings.TrimSpace(signingEmail),
}
}

if setting.Repository.Signing.SigningKey == "" {
return nil, nil
}

return &SigningKey{
KeyID: setting.Repository.Signing.SigningKey,
Format: setting.Repository.Signing.SigningFormat,
}, &Signature{
Name: setting.Repository.Signing.SigningName,
Email: setting.Repository.Signing.SigningEmail,
}
}
18 changes: 18 additions & 0 deletions modules/gitrepo/clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package gitrepo

import (
"context"

"code.gitea.io/gitea/modules/git"
)

func CloneIn(ctx context.Context, dstRepo Repository, from string, opts git.CloneRepoOptions) error {
return git.Clone(ctx, from, repoPath(dstRepo), opts)
}

func CloneOut(ctx context.Context, fromRepo Repository, to string, opts git.CloneRepoOptions) error {
return git.Clone(ctx, repoPath(fromRepo), to, opts)
}
14 changes: 14 additions & 0 deletions modules/gitrepo/commitgraph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package gitrepo

import (
"context"

"code.gitea.io/gitea/modules/git"
)

func WriteCommitGraph(ctx context.Context, repo Repository) error {
return git.WriteCommitGraph(ctx, repoPath(repo))
}
12 changes: 12 additions & 0 deletions modules/gitrepo/gitrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"context"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"

"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/gitcmd"
"code.gitea.io/gitea/modules/reqctx"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -86,3 +89,12 @@ func RenameRepository(ctx context.Context, repo, newRepo Repository) error {
func InitRepository(ctx context.Context, repo Repository, objectFormatName string) error {
return git.InitRepository(ctx, repoPath(repo), true, objectFormatName)
}

func UpdateServerInfo(ctx context.Context, repo Repository) error {
_, _, err := RunCmdBytes(ctx, repo, gitcmd.NewCommand("update-server-info"))
return err
}

func GetRepoFS(repo Repository) fs.FS {
return os.DirFS(repoPath(repo))
}
49 changes: 49 additions & 0 deletions modules/gitrepo/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package gitrepo

import (
"bytes"
"context"
"io"
"os"

"code.gitea.io/gitea/modules/git/gitcmd"
)

func serviceCmd(service string) *gitcmd.Command {
switch service {
case "receive-pack":
return gitcmd.NewCommand("receive-pack")
case "upload-pack":
return gitcmd.NewCommand("upload-pack")
default:
// the service should be checked before invoking this function
panic("unknown service: " + service)
}
}

func StatelessRPC(ctx context.Context, storageRepo Repository, service string, extraEnvs []string, input io.Reader, output io.Writer) (string, error) {
var stderr bytes.Buffer
if err := serviceCmd(service).AddArguments("--stateless-rpc").
AddDynamicArguments(repoPath(storageRepo)).
WithDir(repoPath(storageRepo)).
WithEnv(append(os.Environ(), extraEnvs...)).
WithStderr(&stderr).
WithStdin(input).
WithStdout(output).
WithUseContextTimeout(true).
Run(ctx); err != nil {
return stderr.String(), err
}
return "", nil
}

func StatelessRPCAdvertiseRefs(ctx context.Context, storageRepo Repository, service string, extraEnvs []string) ([]byte, error) {
refs, _, err := serviceCmd(service).AddArguments("--stateless-rpc", "--advertise-refs", ".").
WithEnv(append(os.Environ(), extraEnvs...)).
WithDir(repoPath(storageRepo)).
RunStdBytes(ctx)
return refs, err
}
14 changes: 14 additions & 0 deletions modules/gitrepo/push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package gitrepo

import (
"context"

"code.gitea.io/gitea/modules/git"
)

func Push(ctx context.Context, repo Repository, opts git.PushOptions) error {
return git.Push(ctx, repoPath(repo), opts)
}
14 changes: 14 additions & 0 deletions modules/gitrepo/signing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package gitrepo

import (
"context"

"code.gitea.io/gitea/modules/git"
)

func GetSigningKey(ctx context.Context, repo Repository) (*git.SigningKey, *git.Signature) {
return git.GetSigningKey(ctx, repoPath(repo))
}
Loading