aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-01-28 04:09:51 +0800
committerGitHub <noreply@github.com>2024-01-27 21:09:51 +0100
commit5f82ead13cb7706d3f660271d94de6101cef4119 (patch)
treec10dc0ec9b98992629847f2b98554f3d1c3713ed /services
parent60e4a98ab07dcf3bd86cf630c79e6433c3ef3e84 (diff)
downloadgitea-5f82ead13cb7706d3f660271d94de6101cef4119.tar.gz
gitea-5f82ead13cb7706d3f660271d94de6101cef4119.zip
Simplify how git repositories are opened (#28937)
## Purpose This is a refactor toward building an abstraction over managing git repositories. Afterwards, it does not matter anymore if they are stored on the local disk or somewhere remote. ## What this PR changes We used `git.OpenRepository` everywhere previously. Now, we should split them into two distinct functions: Firstly, there are temporary repositories which do not change: ```go git.OpenRepository(ctx, diskPath) ``` Gitea managed repositories having a record in the database in the `repository` table are moved into the new package `gitrepo`: ```go gitrepo.OpenRepository(ctx, repo_model.Repo) ``` Why is `repo_model.Repository` the second parameter instead of file path? Because then we can easily adapt our repository storage strategy. The repositories can be stored locally, however, they could just as well be stored on a remote server. ## Further changes in other PRs - A Git Command wrapper on package `gitrepo` could be created. i.e. `NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir: repo.RepoPath()}`, the directory should be empty before invoking this method and it can be filled in the function only. #28940 - Remove the `RepoPath()`/`WikiPath()` functions to reduce the possibility of mistakes. --------- Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'services')
-rw-r--r--services/actions/notifier_helper.go3
-rw-r--r--services/asymkey/sign.go7
-rw-r--r--services/automerge/automerge.go7
-rw-r--r--services/convert/pull.go9
-rw-r--r--services/doctor/misc.go3
-rw-r--r--services/migrations/gitea_uploader.go3
-rw-r--r--services/migrations/gitea_uploader_test.go5
-rw-r--r--services/mirror/mirror_pull.go7
-rw-r--r--services/mirror/mirror_push.go21
-rw-r--r--services/pull/check.go3
-rw-r--r--services/pull/comment.go5
-rw-r--r--services/pull/commit_status.go3
-rw-r--r--services/pull/merge_rebase.go3
-rw-r--r--services/pull/merge_squash.go3
-rw-r--r--services/pull/patch.go3
-rw-r--r--services/pull/pull.go17
-rw-r--r--services/pull/pull_test.go5
-rw-r--r--services/pull/review.go3
-rw-r--r--services/release/release.go3
-rw-r--r--services/release/release_test.go10
-rw-r--r--services/repository/adopt.go3
-rw-r--r--services/repository/archiver/archiver.go3
-rw-r--r--services/repository/branch.go9
-rw-r--r--services/repository/create.go3
-rw-r--r--services/repository/files/commit.go3
-rw-r--r--services/repository/files/content.go5
-rw-r--r--services/repository/files/content_test.go5
-rw-r--r--services/repository/files/file_test.go4
-rw-r--r--services/repository/files/patch.go3
-rw-r--r--services/repository/files/update.go3
-rw-r--r--services/repository/fork.go5
-rw-r--r--services/repository/hooks.go6
-rw-r--r--services/repository/lfs.go3
-rw-r--r--services/repository/push.go9
-rw-r--r--services/wiki/wiki.go4
-rw-r--r--services/wiki/wiki_test.go9
36 files changed, 115 insertions, 85 deletions
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index 2a3ffb76f3..9900de3d2e 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -20,6 +20,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -128,7 +129,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return nil
}
- gitRepo, err := git.OpenRepository(context.Background(), input.Repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo)
if err != nil {
return fmt.Errorf("git.OpenRepository: %w", err)
}
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index 0c4aac8156..2f5d76a293 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -13,8 +13,10 @@ import (
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
@@ -167,7 +169,8 @@ Loop:
}
// SignWikiCommit determines if we should sign the commits to this repository wiki
-func SignWikiCommit(ctx context.Context, repoWikiPath string, u *user_model.User) (bool, string, *git.Signature, error) {
+func SignWikiCommit(ctx context.Context, repo *repo_model.Repository, u *user_model.User) (bool, string, *git.Signature, error) {
+ repoWikiPath := repo.WikiPath()
rules := signingModeFromStrings(setting.Repository.Signing.Wiki)
signingKey, sig := SigningKey(ctx, repoWikiPath)
if signingKey == "" {
@@ -201,7 +204,7 @@ Loop:
return false, "", nil, &ErrWontSign{twofa}
}
case parentSigned:
- gitRepo, err := git.OpenRepository(ctx, repoWikiPath)
+ gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo)
if err != nil {
return false, "", nil, err
}
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index bf713c4431..bd427bef9f 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -17,6 +17,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -111,7 +112,7 @@ func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model
}
func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) {
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return nil, err
}
@@ -190,7 +191,7 @@ func handlePull(pullID int64, sha string) {
return
}
- headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
log.Error("OpenRepository %-v: %v", pr.HeadRepo, err)
return
@@ -246,7 +247,7 @@ func handlePull(pullID int64, sha string) {
return
}
- baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository %-v: %v", pr.BaseRepo, err)
return
diff --git a/services/convert/pull.go b/services/convert/pull.go
index 7eebe20426..6d98121ed5 100644
--- a/services/convert/pull.go
+++ b/services/convert/pull.go
@@ -12,6 +12,7 @@ import (
access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
)
@@ -101,7 +102,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr()
}
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
return nil
@@ -127,7 +128,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
if pr.Flow == issues_model.PullRequestFlowAGit {
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err)
return nil
@@ -154,7 +155,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
apiPullRequest.Head.Repository = ToRepo(ctx, pr.HeadRepo, p)
- headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err)
return nil
@@ -190,7 +191,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
- baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
return nil
diff --git a/services/doctor/misc.go b/services/doctor/misc.go
index f0b5966b54..9300c3a25c 100644
--- a/services/doctor/misc.go
+++ b/services/doctor/misc.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -91,7 +92,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++
- r, err := git.OpenRepository(ctx, repo.RepoPath())
+ r, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return err
}
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index 5a4392c667..7b21d9f4d2 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -21,6 +21,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
base_module "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/label"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
@@ -139,7 +140,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
if err != nil {
return err
}
- g.gitRepo, err = git.OpenRepository(g.ctx, r.RepoPath())
+ g.gitRepo, err = gitrepo.OpenRepository(g.ctx, r)
return err
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index 4ec0361dfb..c8102c6b8b 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
@@ -249,7 +250,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
Author: &signature,
Message: "Initial Commit",
}))
- fromGitRepo, err := git.OpenRepository(git.DefaultContext, fromRepo.RepoPath())
+ fromGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, fromRepo)
assert.NoError(t, err)
defer fromGitRepo.Close()
baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef)
@@ -292,7 +293,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
Author: &signature,
Message: "branch2 commit",
}))
- forkGitRepo, err := git.OpenRepository(git.DefaultContext, forkRepo.RepoPath())
+ forkGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, forkRepo)
assert.NoError(t, err)
defer forkGitRepo.Close()
forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef)
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index 6f03e14ab0..3418cf90df 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -13,6 +13,7 @@ import (
system_model "code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -300,7 +301,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err)
}
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err)
return nil, false
@@ -396,7 +397,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
}
log.Trace("SyncMirrors [repo: %-v]: invalidating mirror branch caches...", m.Repo)
- branches, _, err := git.GetBranchesByPath(ctx, m.Repo.RepoPath(), 0, 0)
+ branches, _, err := gitrepo.GetBranchesByPath(ctx, m.Repo, 0, 0)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: failed to GetBranches: %v", m.Repo, err)
return nil, false
@@ -453,7 +454,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
} else {
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
- gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath())
+ gitRepo, err = gitrepo.OpenRepository(ctx, m.Repo)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
return false
diff --git a/services/mirror/mirror_push.go b/services/mirror/mirror_push.go
index b117e79fac..21ba0afeff 100644
--- a/services/mirror/mirror_push.go
+++ b/services/mirror/mirror_push.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -131,7 +132,11 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
- performPush := func(path string) error {
+ performPush := func(repo *repo_model.Repository, isWiki bool) error {
+ path := repo.RepoPath()
+ if isWiki {
+ path = repo.WikiPath()
+ }
remoteURL, err := git.GetRemoteURL(ctx, path, m.RemoteName)
if err != nil {
log.Error("GetRemoteAddress(%s) Error %v", path, err)
@@ -141,7 +146,12 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
if setting.LFS.StartServer {
log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo)
- gitRepo, err := git.OpenRepository(ctx, path)
+ var gitRepo *git.Repository
+ if isWiki {
+ gitRepo, err = gitrepo.OpenWikiRepository(ctx, repo)
+ } else {
+ gitRepo, err = gitrepo.OpenRepository(ctx, repo)
+ }
if err != nil {
log.Error("OpenRepository: %v", err)
return errors.New("Unexpected error")
@@ -171,16 +181,15 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
return nil
}
- err := performPush(m.Repo.RepoPath())
+ err := performPush(m.Repo, false)
if err != nil {
return err
}
if m.Repo.HasWiki() {
- wikiPath := m.Repo.WikiPath()
- _, err := git.GetRemoteAddress(ctx, wikiPath, m.RemoteName)
+ _, err := git.GetRemoteAddress(ctx, m.Repo.WikiPath(), m.RemoteName)
if err == nil {
- err := performPush(wikiPath)
+ err := performPush(m.Repo, true)
if err != nil {
return err
}
diff --git a/services/pull/check.go b/services/pull/check.go
index ebe4c6d61b..dd6c3ed230 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -215,7 +216,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
return nil, fmt.Errorf("GetFullCommitID(%s) in %s: %w", prHeadRef, pr.BaseRepo.FullName(), err)
}
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("%-v OpenRepository: %w", pr.BaseRepo, err)
}
diff --git a/services/pull/comment.go b/services/pull/comment.go
index 14fba52f1e..d538b118d5 100644
--- a/services/pull/comment.go
+++ b/services/pull/comment.go
@@ -9,7 +9,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
)
@@ -17,8 +17,7 @@ import (
// isForcePush will be true if oldCommit isn't on the branch
// Commit on baseBranch will skip
func getCommitIDsFromRepo(ctx context.Context, repo *repo_model.Repository, oldCommitID, newCommitID, baseBranch string) (commitIDs []string, isForcePush bool, err error) {
- repoPath := repo.RepoPath()
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath)
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, false, err
}
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index 39d60380ff..b73816c7eb 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -11,6 +11,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
@@ -116,7 +117,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
}
// check if all required status checks are successful
- headGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
return "", errors.Wrap(err, "OpenRepository")
}
diff --git a/services/pull/merge_rebase.go b/services/pull/merge_rebase.go
index a88f805ef0..ecf376220e 100644
--- a/services/pull/merge_rebase.go
+++ b/services/pull/merge_rebase.go
@@ -9,6 +9,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
)
@@ -57,7 +58,7 @@ func doMergeRebaseFastForward(ctx *mergeContext) error {
}
// Original repo to read template from.
- baseGitRepo, err := git.OpenRepository(ctx, ctx.pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, ctx.pr.BaseRepo)
if err != nil {
log.Error("Unable to get Git repo for rebase: %v", err)
return err
diff --git a/services/pull/merge_squash.go b/services/pull/merge_squash.go
index f52a2301d9..197d8102dd 100644
--- a/services/pull/merge_squash.go
+++ b/services/pull/merge_squash.go
@@ -10,6 +10,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@@ -24,7 +25,7 @@ func getAuthorSignatureSquash(ctx *mergeContext) (*git.Signature, error) {
// Try to get an signature from the same user in one of the commits, as the
// poster email might be private or commits might have a different signature
// than the primary email address of the poster.
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, ctx.tmpBasePath)
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpenPath(ctx, ctx.tmpBasePath)
if err != nil {
log.Error("%-v Unable to open base repository: %v", ctx.pr, err)
return nil, err
diff --git a/services/pull/patch.go b/services/pull/patch.go
index acaff04bda..12b79a0625 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -35,7 +36,7 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
return err
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return fmt.Errorf("OpenRepository: %w", err)
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 930954bdfd..e1ea4357fc 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/container"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
@@ -62,7 +63,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
assigneeCommentMap := make(map[int64]*issues_model.Comment)
// add first push codes comment
- baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return err
}
@@ -269,9 +270,9 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
if err != nil {
return fmt.Errorf("GetRepositoryByIDCtx: %w", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
- return fmt.Errorf("git.OpenRepository: %w", err)
+ return fmt.Errorf("gitrepo.OpenRepository: %w", err)
}
go func() {
// FIXME: graceful: We need to tell the manager we're doing something...
@@ -614,7 +615,7 @@ func CloseBranchPulls(ctx context.Context, doer *user_model.User, repoID int64,
// CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository
func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) error {
- branches, _, err := git.GetBranchesByPath(ctx, repo.RepoPath(), 0, 0)
+ branches, _, err := gitrepo.GetBranchesByPath(ctx, repo, 0, 0)
if err != nil {
return err
}
@@ -671,7 +672,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
}
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
log.Error("Unable to open head repository: Error: %v", err)
return ""
@@ -845,7 +846,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList
}
gitRepo, ok := gitRepos[issue.RepoID]
if !ok {
- gitRepo, err = git.OpenRepository(ctx, issue.Repo.RepoPath())
+ gitRepo, err = gitrepo.OpenRepository(ctx, issue.Repo)
if err != nil {
log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err)
continue
@@ -882,7 +883,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
if err = pr.LoadBaseRepo(ctx); err != nil {
return false, err
}
- baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return false, err
}
@@ -902,7 +903,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
} else {
var closer io.Closer
- headGitRepo, closer, err = git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, closer, err = gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
return false, err
}
diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go
index d63227a7d5..787910bf76 100644
--- a/services/pull/pull_test.go
+++ b/services/pull/pull_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"github.com/stretchr/testify/assert"
)
@@ -41,7 +42,7 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -71,7 +72,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/services/pull/review.go b/services/pull/review.go
index e48f380154..d4ea975612 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -170,7 +171,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
if err := pr.LoadBaseRepo(ctx); err != nil {
return nil, fmt.Errorf("LoadBaseRepo: %w", err)
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("RepositoryFromContextOrOpen: %w", err)
}
diff --git a/services/release/release.go b/services/release/release.go
index f17682ae0f..c1d13126f0 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
@@ -168,7 +169,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
}
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return err
}
diff --git a/services/release/release_test.go b/services/release/release_test.go
index 4b57262981..3d0681f1e1 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/services/attachment"
_ "code.gitea.io/gitea/models/actions"
@@ -29,9 +30,8 @@ func TestRelease_Create(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -135,9 +135,8 @@ func TestRelease_Update(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -278,9 +277,8 @@ func TestRelease_createTag(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index 2e9b0c822f..bfb965063f 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -17,6 +17,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -126,7 +127,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
repo.IsEmpty = false
// Don't bother looking this repo in the context it won't be there
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go
index c2ad4d484a..01c58f0ce4 100644
--- a/services/repository/archiver/archiver.go
+++ b/services/repository/archiver/archiver.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -209,7 +210,7 @@ func doArchive(ctx context.Context, r *ArchiveRequest) (*repo_model.RepoArchiver
return nil, fmt.Errorf("archiver.LoadRepo failed: %w", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/branch.go b/services/repository/branch.go
index c1e6625ed4..e2e50297af 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -17,6 +17,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
@@ -160,7 +161,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
if pr.HasMerged {
baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID]
if !ok {
- baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
@@ -190,13 +191,9 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
}, nil
}
-func GetBranchCommitID(ctx context.Context, repo *repo_model.Repository, branch string) (string, error) {
- return git.GetBranchCommitID(ctx, repo.RepoPath(), branch)
-}
-
// checkBranchName validates branch name with existing repository branches
func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error {
- _, err := git.WalkReferences(ctx, repo.RepoPath(), func(_, refName string) error {
+ _, err := gitrepo.WalkReferences(ctx, repo, func(_, refName string) error {
branchRefName := strings.TrimPrefix(refName, git.BranchPrefix)
switch {
case branchRefName == name:
diff --git a/services/repository/create.go b/services/repository/create.go
index 0e89573343..a648c0d816 100644
--- a/services/repository/create.go
+++ b/services/repository/create.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -175,7 +176,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
if len(opts.DefaultBranch) > 0 {
repo.DefaultBranch = opts.DefaultBranch
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index 048e41e6fd..16a15e06a7 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -12,6 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/automerge"
)
@@ -23,7 +24,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
repoPath := repo.RepoPath()
// confirm that commit is exist
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
}
diff --git a/services/repository/files/content.go b/services/repository/files/content.go
index 30d62fbcdf..c278d7f835 100644
--- a/services/repository/files/content.go
+++ b/services/repository/files/content.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -58,7 +59,7 @@ func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, treePat
}
treePath = cleanTreePath
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
@@ -133,7 +134,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
}
treePath = cleanTreePath
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go
index 3ad3e3ab98..d50847789a 100644
--- a/services/repository/files/content_test.go
+++ b/services/repository/files/content_test.go
@@ -6,10 +6,9 @@ package files
import (
"testing"
- repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
_ "code.gitea.io/gitea/models/actions"
@@ -235,7 +234,7 @@ func TestGetBlobBySHA(t *testing.T) {
ctx.SetParams(":id", "1")
ctx.SetParams(":sha", sha)
- gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
+ gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
t.Fail()
}
diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go
index 4e67ad1410..675ddbddb3 100644
--- a/services/repository/files/file_test.go
+++ b/services/repository/files/file_test.go
@@ -8,7 +8,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -109,7 +109,7 @@ func TestGetFileResponseFromCommit(t *testing.T) {
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
treePath := "README.md"
- gitRepo, _ := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(ctx, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
expectedFileResponse := getExpectedFileResponse()
diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go
index 14f8caaa8c..f6d5643dc9 100644
--- a/services/repository/files/patch.go
+++ b/services/repository/files/patch.go
@@ -13,6 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
asymkey_service "code.gitea.io/gitea/services/asymkey"
@@ -42,7 +43,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode
opts.NewBranch = opts.OldBranch
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return err
}
diff --git a/services/repository/files/update.go b/services/repository/files/update.go
index 1892043304..f223daf3a9 100644
--- a/services/repository/files/update.go
+++ b/services/repository/files/update.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -78,7 +79,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
opts.NewBranch = opts.OldBranch
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/fork.go b/services/repository/fork.go
index a8ff2717b0..f9c13a109e 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.go
@@ -14,6 +14,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/structs"
@@ -167,7 +168,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
return fmt.Errorf("createDelegateHooks: %w", err)
}
- gitRepo, err := git.OpenRepository(txCtx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(txCtx, repo)
if err != nil {
return fmt.Errorf("OpenRepository: %w", err)
}
@@ -190,7 +191,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
log.Error("Copy language stat from oldRepo failed: %v", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Error("Open created git repository failed: %v", err)
} else {
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
index 7b82f36b43..97e9e290a3 100644
--- a/services/repository/hooks.go
+++ b/services/repository/hooks.go
@@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/webhook"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -52,13 +52,13 @@ func SyncRepositoryHooks(ctx context.Context) error {
// GenerateGitHooks generates git hooks from a template repository
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
- generateGitRepo, err := git.OpenRepository(ctx, generateRepo.RepoPath())
+ generateGitRepo, err := gitrepo.OpenRepository(ctx, generateRepo)
if err != nil {
return err
}
defer generateGitRepo.Close()
- templateGitRepo, err := git.OpenRepository(ctx, templateRepo.RepoPath())
+ templateGitRepo, err := gitrepo.OpenRepository(ctx, templateRepo)
if err != nil {
return err
}
diff --git a/services/repository/lfs.go b/services/repository/lfs.go
index b437fda15d..4504f796bd 100644
--- a/services/repository/lfs.go
+++ b/services/repository/lfs.go
@@ -12,6 +12,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -69,7 +70,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
}
}()
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Error("Unable to open git repository %-v: %v", repo, err)
return err
diff --git a/services/repository/push.go b/services/repository/push.go
index e86eebde81..bedcf6f252 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -86,17 +87,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err)
}
- repoPath := repo.RepoPath()
-
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
- return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
+ return fmt.Errorf("OpenRepository[%s]: %w", repo.FullName(), err)
}
defer gitRepo.Close()
objectFormat, err := gitRepo.GetObjectFormat()
if err != nil {
- return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repoPath, err)
+ return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repo.FullName(), err)
}
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index ce54a00da7..50d52d3140 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -191,7 +191,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer)
+ sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
@@ -314,7 +314,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer)
+ sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index 277fa086ac..59c77060f2 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
_ "code.gitea.io/gitea/models/actions"
@@ -164,7 +165,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
webPath := UserTitleToWebPath("", userTitle)
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}
@@ -212,7 +213,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
assert.NoError(t, err)
masterTree, err := gitRepo.GetTree(DefaultBranch)
assert.NoError(t, err)
@@ -236,7 +237,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}
@@ -251,7 +252,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}