Skip to content

Commit c397f49

Browse files
committed
fix
1 parent c858a19 commit c397f49

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

modules/gitrepo/gitrepo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type Repository interface {
2020
RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
2121
}
2222

23-
// RelativePath should be an unix style path like username/reponame.git
23+
// RelativePath should be a unix style path like username/reponame.git
2424
// This method should change it according to the current OS.
25-
func repoPath(repo Repository) string {
25+
var repoPath = func(repo Repository) string {
2626
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.RelativePath()))
2727
}
2828

modules/gitrepo/main_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,27 @@
44
package gitrepo
55

66
import (
7-
"fmt"
87
"os"
98
"path/filepath"
109
"testing"
1110

11+
"code.gitea.io/gitea/modules/log"
1212
"code.gitea.io/gitea/modules/setting"
13-
"code.gitea.io/gitea/modules/util"
14-
)
15-
16-
const (
17-
testReposDir = "../git/tests/repos/"
13+
"code.gitea.io/gitea/modules/tempdir"
1814
)
1915

2016
func TestMain(m *testing.M) {
21-
// since all test repository is defined by testReposDir, we need to set it here
22-
// So that all functions could work properly because Repository will only contain
23-
// Relative Path to RepoRootPath
24-
setting.RepoRootPath, _ = filepath.Abs(testReposDir)
25-
// TODO: run command requires a home directory, we could set it to a temp dir
26-
gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
17+
gitHomePath, cleanup, err := tempdir.OsTempDir("gitea-test").MkdirTempRandom("git-home")
2718
if err != nil {
28-
panic(fmt.Errorf("unable to create temp dir: %w", err))
19+
log.Fatal("Unable to create temp dir: %v", err)
2920
}
30-
defer util.RemoveAll(gitHomePath)
31-
setting.Git.HomePath = gitHomePath
21+
defer cleanup()
3222

33-
exitStatus := m.Run()
34-
os.Exit(exitStatus)
23+
// resolve repository path relative to the test directory
24+
repoPath = func(repo Repository) string {
25+
return filepath.Join("../git/tests/repos", repo.RelativePath())
26+
}
27+
28+
setting.Git.HomePath = gitHomePath
29+
os.Exit(m.Run())
3530
}

services/pull/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
469469
return
470470
}
471471
for _, pr := range prs {
472-
pr.BaseRepo = baseRepo // avoid loading again
472+
pr.BaseRepo = baseRepo // avoid loading again // FIXME: why only here does so but the code above doesn't do so
473473
divergence, err := GetDiverging(ctx, pr)
474474
if err != nil {
475475
if git_model.IsErrBranchNotExist(err) && !gitrepo.IsBranchExist(ctx, pr.HeadRepo, pr.HeadBranch) {
@@ -491,7 +491,7 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
491491
// checkIfPRContentChanged checks if diff to target branch has changed by push
492492
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
493493
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
494-
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr)
494+
prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr) // FIXME: why it still needs to create a temp repo, since the alongside calls like GetDiverging doesn't do so anymore
495495
if err != nil {
496496
log.Error("CreateTemporaryRepoForPR %-v: %v", pr, err)
497497
return false, err

services/pull/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Update(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.
3939
return fmt.Errorf("unable to load BaseRepo for PR[%d] during update-by-merge: %w", pr.ID, err)
4040
}
4141

42-
if pr.ID > 0 { // only a real PR needs to check this
42+
if pr.ID > 0 { // only a real PR needs to check this FIXME: why it needs this check?
4343
diffCount, err := GetDiverging(ctx, pr)
4444
if err != nil {
4545
return err

services/repository/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
187187
var err error
188188
divergence, err = gitrepo.GetDivergingCommits(ctx, repo, repo.DefaultBranch, git.BranchPrefix+branchName)
189189
if err != nil {
190-
log.Error("CountDivergingCommits: %v", err)
190+
log.Error("GetDivergingCommits: %v", err)
191191
} else {
192192
if err = putDivergenceFromCache(repo.ID, dbBranch.Name, divergence); err != nil {
193193
log.Error("putDivergenceFromCache: %v", err)

0 commit comments

Comments
 (0)