mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 16:17:41 -04:00 
			
		
		
		
	This PR moved git attributes related code to `modules/git/attribute` sub package and moved language stats related code to `modules/git/languagestats` sub package to make it easier to maintain. And it also introduced a performance improvement which use the `git check-attr --source` which can be run in a bare git repository so that we don't need to create a git index file. The new parameter need a git version >= 2.40 . If git version less than 2.40, it will fall back to previous implementation. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: yp05327 <576951401@qq.com>
		
			
				
	
	
		
			42 lines
		
	
	
		
			889 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			889 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2025 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package attribute
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"testing"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/git"
 | |
| 	"code.gitea.io/gitea/modules/setting"
 | |
| 	"code.gitea.io/gitea/modules/util"
 | |
| )
 | |
| 
 | |
| func testRun(m *testing.M) error {
 | |
| 	gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
 | |
| 	if err != nil {
 | |
| 		return fmt.Errorf("unable to create temp dir: %w", err)
 | |
| 	}
 | |
| 	defer util.RemoveAll(gitHomePath)
 | |
| 	setting.Git.HomePath = gitHomePath
 | |
| 
 | |
| 	if err = git.InitFull(context.Background()); err != nil {
 | |
| 		return fmt.Errorf("failed to call Init: %w", err)
 | |
| 	}
 | |
| 
 | |
| 	exitCode := m.Run()
 | |
| 	if exitCode != 0 {
 | |
| 		return fmt.Errorf("run test failed, ExitCode=%d", exitCode)
 | |
| 	}
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func TestMain(m *testing.M) {
 | |
| 	if err := testRun(m); err != nil {
 | |
| 		_, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
 | |
| 		os.Exit(1)
 | |
| 	}
 | |
| }
 |