Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git_tree.go « testhelper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9521d80e349af826bba729ebde4f59fe725b02ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package testhelper

import (
	"bytes"
	"testing"

	"github.com/stretchr/testify/require"
)

type TreeEntry struct {
	Mode    string
	Path    string
	Content string
}

func RequireTree(t testing.TB, repoPath, treeish string, expectedEntries []TreeEntry) {
	t.Helper()

	var actualEntries []TreeEntry

	output := bytes.TrimSpace(MustRunCommand(t, nil, "git", "-C", repoPath, "ls-tree", "-r", treeish))

	if len(output) > 0 {
		for _, line := range bytes.Split(output, []byte("\n")) {
			// Format: <mode> SP <type> SP <object> TAB <file>
			tabSplit := bytes.Split(line, []byte("\t"))
			spaceSplit := bytes.Split(tabSplit[0], []byte(" "))
			path := string(tabSplit[1])
			actualEntries = append(actualEntries, TreeEntry{
				Mode:    string(spaceSplit[0]),
				Path:    path,
				Content: string(MustRunCommand(t, nil, "git", "-C", repoPath, "show", treeish+":"+path)),
			})
		}
	}

	require.Equal(t, expectedEntries, actualEntries)
}