Skip to content

Commit b32101f

Browse files
committed
try test again
1 parent 9f89b2f commit b32101f

File tree

8 files changed

+18
-5
lines changed

8 files changed

+18
-5
lines changed

integrations/integration_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ func initIntegrationTest() {
174174
setting.LoadForTest()
175175
setting.Repository.DefaultBranch = "master" // many test code still assume that default branch is called "master"
176176
_ = util.RemoveAll(repo_module.LocalCopyPath())
177+
178+
if err := git.InitOnceWithSync(context.Background()); err != nil {
179+
log.Fatal("git.InitOnceWithSync: %v", err)
180+
}
177181
git.CheckLFSVersion()
182+
178183
setting.InitDBConfig()
179184
if err := storage.Init(); err != nil {
180185
fmt.Printf("Init storage failed: %v", err)
@@ -275,7 +280,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
275280
assert.NoError(t, unittest.LoadFixtures())
276281
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
277282
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
278-
assert.NoError(t, git.InitOnceWithSync(context.Background()))
283+
assert.NoError(t, git.InitOnceWithSync(context.Background())) // the gitconfig has been removed above, so sync the gitconfig again
279284
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
280285
if err != nil {
281286
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
@@ -576,7 +581,7 @@ func resetFixtures(t *testing.T) {
576581
assert.NoError(t, unittest.LoadFixtures())
577582
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
578583
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
579-
assert.NoError(t, git.InitOnceWithSync(context.Background()))
584+
assert.NoError(t, git.InitOnceWithSync(context.Background())) // the gitconfig has been removed above, so sync the gitconfig again
580585
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
581586
if err != nil {
582587
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

integrations/migration-test/migration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func initMigrationTest(t *testing.T) func() {
6262
assert.True(t, len(setting.RepoRootPath) != 0)
6363
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
6464
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
65-
assert.NoError(t, git.InitOnceWithSync(context.Background()))
6665
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
6766
if err != nil {
6867
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
@@ -83,6 +82,7 @@ func initMigrationTest(t *testing.T) func() {
8382
}
8483
}
8584

85+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
8686
git.CheckLFSVersion()
8787
setting.InitDBConfig()
8888
setting.NewLogServices(true)

models/migrations/migrations_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func prepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.En
203203
deferFn := PrintCurrentTest(t, ourSkip)
204204
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
205205
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
206-
assert.NoError(t, git.InitOnceWithSync(context.Background()))
206+
assert.NoError(t, git.InitOnceWithSync(context.Background())) // the gitconfig has been removed above, so sync the gitconfig again
207207
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
208208
if err != nil {
209209
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

models/unittest/testdb.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
117117
if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
118118
fatalTestError("util.CopyDir: %v\n", err)
119119
}
120+
120121
if err = git.InitOnceWithSync(context.Background()); err != nil {
121122
fatalTestError("git.Init: %v\n", err)
122123
}
124+
git.CheckLFSVersion()
123125

124126
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
125127
if err != nil {
@@ -202,7 +204,7 @@ func PrepareTestEnv(t testing.TB) {
202204
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
203205
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
204206
assert.NoError(t, CopyDir(metaPath, setting.RepoRootPath))
205-
assert.NoError(t, git.InitOnceWithSync(context.Background()))
207+
assert.NoError(t, git.InitOnceWithSync(context.Background())) // the gitconfig has been removed above, so sync the gitconfig again
206208

207209
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
208210
assert.NoError(t, err)

modules/git/git.go

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func HomeDir() string {
134134
tmpHomeDir := filepath.Join(os.TempDir(), "gitea-temp-home")
135135
log.Error("Git's HomeDir is empty (RepoRootPath is empty), the git module is not initialized correctly, using a temp HomeDir (%s) temporarily", tmpHomeDir)
136136
return tmpHomeDir
137+
138+
// the Fatal will cause some CI failures (root reason is still unknown), need to be investigated more in the future
139+
// log.Fatal("Can not get Git's HomeDir (RepoRootPath is empty), the setting and git modules are not initialized correctly")
137140
}
138141
return setting.RepoRootPath
139142
}

modules/git/repo_language_stats_gogit.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
4545

4646
var checker *CheckAttributeReader
4747

48+
// this code block is refactored from old code "if (git version ...)", keep the block to limit the variable scope
4849
{
4950
indexFilename, workTree, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)
5051
if err == nil {

modules/git/repo_language_stats_nogogit.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
6565

6666
var checker *CheckAttributeReader
6767

68+
// this code block is refactored from old code "if (git version ...)", keep the block to limit the variable scope
6869
{
6970
indexFilename, worktree, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)
7071
if err == nil {

services/gitdiff/gitdiff.go

+1
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
14181418

14191419
var checker *git.CheckAttributeReader
14201420

1421+
// this code block is refactored from old code "if (git version ...)", keep the block to limit the variable scope
14211422
{
14221423
indexFilename, worktree, deleteTemporaryFile, err := gitRepo.ReadTreeToTemporaryIndex(opts.AfterCommitID)
14231424
if err == nil {

0 commit comments

Comments
 (0)