mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-28 10:04:49 +01:00 
			
		
		
		
	Refactor Git command functions to use WithXXX methods instead of exposing RunOpts. This change simplifies reuse across gitrepo and improves consistency, encapsulation, and maintainability of command options. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2024 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package git
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 	"testing"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/git/gitcmd"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| )
 | |
| 
 | |
| func TestGetTemplateSubmoduleCommits(t *testing.T) {
 | |
| 	testRepoPath := filepath.Join(testReposDir, "repo4_submodules")
 | |
| 	submodules, err := GetTemplateSubmoduleCommits(t.Context(), testRepoPath)
 | |
| 	require.NoError(t, err)
 | |
| 
 | |
| 	assert.Len(t, submodules, 2)
 | |
| 
 | |
| 	assert.Equal(t, "<°)))><", submodules[0].Path)
 | |
| 	assert.Equal(t, "d2932de67963f23d43e1c7ecf20173e92ee6c43c", submodules[0].Commit)
 | |
| 
 | |
| 	assert.Equal(t, "libtest", submodules[1].Path)
 | |
| 	assert.Equal(t, "1234567890123456789012345678901234567890", submodules[1].Commit)
 | |
| }
 | |
| 
 | |
| func TestAddTemplateSubmoduleIndexes(t *testing.T) {
 | |
| 	ctx := t.Context()
 | |
| 	tmpDir := t.TempDir()
 | |
| 	var err error
 | |
| 	_, _, err = gitcmd.NewCommand("init").WithDir(tmpDir).RunStdString(ctx)
 | |
| 	require.NoError(t, err)
 | |
| 	_ = os.Mkdir(filepath.Join(tmpDir, "new-dir"), 0o755)
 | |
| 	err = AddTemplateSubmoduleIndexes(ctx, tmpDir, []TemplateSubmoduleCommit{{Path: "new-dir", Commit: "1234567890123456789012345678901234567890"}})
 | |
| 	require.NoError(t, err)
 | |
| 	_, _, err = gitcmd.NewCommand("add", "--all").WithDir(tmpDir).RunStdString(ctx)
 | |
| 	require.NoError(t, err)
 | |
| 	_, _, err = gitcmd.NewCommand("-c", "user.name=a", "-c", "user.email=b", "commit", "-m=test").WithDir(tmpDir).RunStdString(ctx)
 | |
| 	require.NoError(t, err)
 | |
| 	submodules, err := GetTemplateSubmoduleCommits(t.Context(), tmpDir)
 | |
| 	require.NoError(t, err)
 | |
| 	assert.Len(t, submodules, 1)
 | |
| 	assert.Equal(t, "new-dir", submodules[0].Path)
 | |
| 	assert.Equal(t, "1234567890123456789012345678901234567890", submodules[0].Commit)
 | |
| }
 |