gittest

package
v14.9.0-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GlRepository is the default repository name for newly created test
	// repos.
	GlRepository = "project-1"
	// GlProjectPath is the default project path for newly created test
	// repos.
	GlProjectPath = "gitlab-org/gitlab-test"

	// SeedGitLabTest is the path of the gitlab-test.git repository in _build/testrepos.
	SeedGitLabTest = "gitlab-test.git"
)
View Source
const (
	// GlID is the ID of the default user.
	GlID = "user-123"

	// Timezone is the Timezone of the default user.
	Timezone = "Asia/Shanghai"
	// TimezoneOffset is ISO 8601-like format of the default user Timezone.
	TimezoneOffset = "+0800"
)

Variables

View Source
var CommitsByID = map[string]*gitalypb.GitCommit{
	"0031876facac3f2b2702a0e53a26e89939a42209": {
		Id:        "0031876facac3f2b2702a0e53a26e89939a42209",
		Subject:   []byte("Merge branch 'few-commits-4' into few-commits-2"),
		Body:      []byte("Merge branch 'few-commits-4' into few-commits-2\n"),
		Author:    ahmadSherif(1500320762),
		Committer: ahmadSherif(1500320762),
		ParentIds: []string{
			"bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb",
			"48ca272b947f49eee601639d743784a176574a09",
		},
		BodySize: 48,
		TreeId:   "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"48ca272b947f49eee601639d743784a176574a09": {
		Id:        "48ca272b947f49eee601639d743784a176574a09",
		Subject:   []byte("Commit #9 alternate"),
		Body:      []byte("Commit #9 alternate\n"),
		Author:    ahmadSherif(1500320271),
		Committer: ahmadSherif(1500320271),
		ParentIds: []string{"335bc94d5b7369b10251e612158da2e4a4aaa2a5"},
		BodySize:  20,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"335bc94d5b7369b10251e612158da2e4a4aaa2a5": {
		Id:        "335bc94d5b7369b10251e612158da2e4a4aaa2a5",
		Subject:   []byte("Commit #8 alternate"),
		Body:      []byte("Commit #8 alternate\n"),
		Author:    ahmadSherif(1500320269),
		Committer: ahmadSherif(1500320269),
		ParentIds: []string{"1039376155a0d507eba0ea95c29f8f5b983ea34b"},
		BodySize:  20,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb": {
		Id:        "bf6e164cac2dc32b1f391ca4290badcbe4ffc5fb",
		Subject:   []byte("Commit #10"),
		Body:      []byte("Commit #10\n"),
		Author:    ahmadSherif(1500320272),
		Committer: ahmadSherif(1500320272),
		ParentIds: []string{"9d526f87b82e2b2fd231ca44c95508e5e85624ca"},
		BodySize:  11,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"9d526f87b82e2b2fd231ca44c95508e5e85624ca": {
		Id:        "9d526f87b82e2b2fd231ca44c95508e5e85624ca",
		Subject:   []byte("Commit #9"),
		Body:      []byte("Commit #9\n"),
		Author:    ahmadSherif(1500320270),
		Committer: ahmadSherif(1500320270),
		ParentIds: []string{"1039376155a0d507eba0ea95c29f8f5b983ea34b"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1039376155a0d507eba0ea95c29f8f5b983ea34b": {
		Id:        "1039376155a0d507eba0ea95c29f8f5b983ea34b",
		Subject:   []byte("Commit #8"),
		Body:      []byte("Commit #8\n"),
		Author:    ahmadSherif(1500320268),
		Committer: ahmadSherif(1500320268),
		ParentIds: []string{"54188278422b1fa877c2e71c4e37fc6640a58ad1"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"54188278422b1fa877c2e71c4e37fc6640a58ad1": {
		Id:        "54188278422b1fa877c2e71c4e37fc6640a58ad1",
		Subject:   []byte("Commit #7"),
		Body:      []byte("Commit #7\n"),
		Author:    ahmadSherif(1500320266),
		Committer: ahmadSherif(1500320266),
		ParentIds: []string{"8b9270332688d58e25206601900ee5618fab2390"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"8b9270332688d58e25206601900ee5618fab2390": {
		Id:        "8b9270332688d58e25206601900ee5618fab2390",
		Subject:   []byte("Commit #6"),
		Body:      []byte("Commit #6\n"),
		Author:    ahmadSherif(1500320264),
		Committer: ahmadSherif(1500320264),
		ParentIds: []string{"f9220df47bce1530e90c189064d301bfc8ceb5ab"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"f9220df47bce1530e90c189064d301bfc8ceb5ab": {
		Id:        "f9220df47bce1530e90c189064d301bfc8ceb5ab",
		Subject:   []byte("Commit #5"),
		Body:      []byte("Commit #5\n"),
		Author:    ahmadSherif(1500320262),
		Committer: ahmadSherif(1500320262),
		ParentIds: []string{"40d408f89c1fd26b7d02e891568f880afe06a9f8"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"40d408f89c1fd26b7d02e891568f880afe06a9f8": {
		Id:        "40d408f89c1fd26b7d02e891568f880afe06a9f8",
		Subject:   []byte("Commit #4"),
		Body:      []byte("Commit #4\n"),
		Author:    ahmadSherif(1500320260),
		Committer: ahmadSherif(1500320260),
		ParentIds: []string{"df914c609a1e16d7d68e4a61777ff5d6f6b6fde3"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"df914c609a1e16d7d68e4a61777ff5d6f6b6fde3": {
		Id:        "df914c609a1e16d7d68e4a61777ff5d6f6b6fde3",
		Subject:   []byte("Commit #3"),
		Body:      []byte("Commit #3\n"),
		Author:    ahmadSherif(1500320258),
		Committer: ahmadSherif(1500320258),
		ParentIds: []string{"6762605237fc246ae146ac64ecb467f71d609120"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"6762605237fc246ae146ac64ecb467f71d609120": {
		Id:        "6762605237fc246ae146ac64ecb467f71d609120",
		Subject:   []byte("Commit #2"),
		Body:      []byte("Commit #2\n"),
		Author:    ahmadSherif(1500320256),
		Committer: ahmadSherif(1500320256),
		ParentIds: []string{"79b06233d3dc769921576771a4e8bee4b439595d"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"79b06233d3dc769921576771a4e8bee4b439595d": {
		Id:        "79b06233d3dc769921576771a4e8bee4b439595d",
		Subject:   []byte("Commit #1"),
		Body:      []byte("Commit #1\n"),
		Author:    ahmadSherif(1500320254),
		Committer: ahmadSherif(1500320254),
		ParentIds: []string{"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"},
		BodySize:  10,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863": {
		Id:        "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
		Subject:   []byte("Initial commit"),
		Body:      []byte("Initial commit\n"),
		Author:    dmitriyZaporozhets(1393488198),
		Committer: dmitriyZaporozhets(1393488198),
		ParentIds: nil,
		BodySize:  15,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"304d257dcb821665ab5110318fc58a007bd104ed": {
		Id:        "304d257dcb821665ab5110318fc58a007bd104ed",
		Subject:   []byte("Commit #11"),
		Body:      []byte("Commit #11\n"),
		Author:    ahmadSherif(1500322381),
		Committer: ahmadSherif(1500322381),
		ParentIds: []string{"1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"},
		BodySize:  11,
		TreeId:    "91639b9835ff541f312fd2735f639a50bf35d472",
	},
	"1e292f8fedd741b75372e19097c76d327140c312": {
		Id:        "1e292f8fedd741b75372e19097c76d327140c312",
		Subject:   []byte("Merge branch 'cherry-pikc-ce369011' into 'master'"),
		Body:      []byte("Merge branch 'cherry-pikc-ce369011' into 'master'\n\nAdd file with a _flattable_ path\n\n See merge request gitlab-org/gitlab-test!35\n"),
		Author:    drewBlessing(1540830087),
		Committer: drewBlessing(1540830087),
		ParentIds: []string{
			"79b06233d3dc769921576771a4e8bee4b439595d",
			"c1c67abbaf91f624347bb3ae96eabe3a1b742478",
		},
		BodySize: 388,
		TreeId:   "07f8147e8e73aab6c935c296e8cdc5194dee729b",
	},
	"60ecb67744cb56576c30214ff52294f8ce2def98": {
		Id:        "60ecb67744cb56576c30214ff52294f8ce2def98",
		Subject:   []byte("Merge branch 'lfs' into 'master'"),
		Body:      []byte("Merge branch 'lfs' into 'master'\n\nAdd LFS tracking of \"*.lfs\" to .gitattributes\n\nSee merge request gitlab-org/gitlab-test!28"),
		Author:    stanHu(1515740810),
		Committer: stanHu(1515740810),
		ParentIds: []string{
			"e63f41fe459e62e1228fcef60d7189127aeba95a",
			"55bc176024cfa3baaceb71db584c7e5df900ea65",
		},
		BodySize: 124,
		TreeId:   "7e2f26d033ee47cd0745649d1a28277c56197921",
	},
	"e63f41fe459e62e1228fcef60d7189127aeba95a": {
		Id:        "e63f41fe459e62e1228fcef60d7189127aeba95a",
		Subject:   []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'"),
		Body:      []byte("Merge branch 'gitlab-test-usage-dev-testing-docs' into 'master'\r\n\r\nUpdate README.md to include `Usage in testing and development`\r\n\r\nSee merge request !21"),
		Author:    seanMcGivern(1491906794),
		Committer: seanMcGivern(1491906794),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
			"4a24d82dbca5c11c61556f3b35ca472b7463187e",
		},
		BodySize: 154,
		TreeId:   "86ec18bfe87ad42a782fdabd8310f9b7ac750f51",
	},
	"55bc176024cfa3baaceb71db584c7e5df900ea65": {
		Id:        "55bc176024cfa3baaceb71db584c7e5df900ea65",
		Subject:   []byte("LFS tracks \"*.lfs\" through .gitattributes"),
		Body:      []byte("LFS tracks \"*.lfs\" through .gitattributes\n"),
		Author:    jamesEdwardsJones(1515687321),
		Committer: jamesEdwardsJones(1515738427),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
		},
		BodySize: 42,
		TreeId:   "1970c07e0e1ce7fcf82edc2e3792564bd8ea3744",
	},
	"4a24d82dbca5c11c61556f3b35ca472b7463187e": {
		Id:        "4a24d82dbca5c11c61556f3b35ca472b7463187e",
		Subject:   []byte("Update README.md to include `Usage in testing and development`"),
		Body:      []byte("Update README.md to include `Usage in testing and development`"),
		Author:    lukeBennett(1491905339),
		Committer: lukeBennett(1491905339),
		ParentIds: []string{
			"b83d6e391c22777fca1ed3012fce84f633d7fed0",
		},
		BodySize: 62,
		TreeId:   "86ec18bfe87ad42a782fdabd8310f9b7ac750f51",
	},
	"ce369011c189f62c815f5971d096b26759bab0d1": {
		Id:        "ce369011c189f62c815f5971d096b26759bab0d1",
		Subject:   []byte("Add file with a _flattable_ path"),
		Body:      []byte("Add file with a _flattable_ path\n"),
		Author:    alejandroRodriguez(1504382739),
		Committer: alejandroRodriguez(1504397760),
		ParentIds: []string{
			"913c66a37b4a45b9769037c55c2d238bd0942d2e",
		},
		BodySize: 33,
		TreeId:   "729bb692f55d49149609dd1ceaaf1febbdec7d0d",
	},
	"ca47bfd5e930148c42ed74c3b561a8783e381f7f": {
		Id:     "ca47bfd5e930148c42ed74c3b561a8783e381f7f",
		TreeId: "a5d06eba4fd37a4f7a39863c226e5ff66010deed",
		ParentIds: []string{
			"00850ec866c95e6516fca79614af7a868f6d3f43",
		},
		Subject:  []byte("Add Modula-2 source file for language detection"),
		Body:     []byte("Add Modula-2 source file for language detection\n"),
		BodySize: 48,
		Author: &gitalypb.CommitAuthor{
			Name:     []byte("Jacob Vosmaer"),
			Email:    []byte("jacob@gitlab.com"),
			Date:     &timestamppb.Timestamp{Seconds: 1501503403},
			Timezone: []byte("+0200"),
		},
		Committer: &gitalypb.CommitAuthor{
			Name:     []byte("Ahmad Sherif"),
			Email:    []byte("me@ahmadsherif.com"),
			Date:     &timestamppb.Timestamp{Seconds: 1521033060},
			Timezone: []byte("+0100"),
		},
	},
}

CommitsByID is a map of GitCommit structures by their respective IDs.

View Source
var TestUser = &gitalypb.User{
	Name:       []byte("Jane Doe"),
	Email:      []byte("janedoe@gitlab.com"),
	GlId:       GlID,
	GlUsername: "janedoe",
	Timezone:   Timezone,
}

TestUser is the default user for tests.

Functions

func AddWorktree

func AddWorktree(t testing.TB, cfg config.Cfg, repoPath string, worktreeName string)

AddWorktree creates a worktree in the repository path for tests

func AddWorktreeArgs

func AddWorktreeArgs(repoPath, worktreeName string) []string

AddWorktreeArgs returns git command arguments for adding a worktree at the specified repo

func BundleTestRepo added in v14.4.0

func BundleTestRepo(t testing.TB, cfg config.Cfg, sourceRepo, bundlePath string, patterns ...string)

BundleTestRepo creates a bundle of a local test repo. E.g. `gitlab-test.git`. `patterns` define the bundle contents as per `git-rev-list-args`. If there are no patterns then `--all` is assumed.

func CaptureHookEnv

func CaptureHookEnv(t testing.TB, cfg config.Cfg) (git.CommandFactory, string)

CaptureHookEnv creates a Git command factory which injects a bogus 'update' Git hook to sniff out what environment variables get set for hooks.

func ChecksumTestRepo added in v14.5.0

func ChecksumTestRepo(t testing.TB, cfg config.Cfg, sourceRepo string) *git.Checksum

ChecksumTestRepo calculates the checksum of a local test repo. E.g. `gitlab-test.git`.

func CloneRepo added in v14.2.0

func CloneRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...CloneRepoOpts) (*gitalypb.Repository, string)

CloneRepo clones a new copy of test repository under a subdirectory in the storage root. You can either pass no or exactly one CloneRepoOpts.

func CommitEqual

func CommitEqual(t testing.TB, expected, actual *gitalypb.GitCommit)

CommitEqual tests if two `GitCommit`s are equal

func CreateRepository added in v14.8.0

func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs ...CreateRepositoryConfig) (*gitalypb.Repository, string)

CreateRepository creates a new repository and returns it and its absolute path.

func Exec

func Exec(t testing.TB, cfg config.Cfg, args ...string) []byte

Exec runs a git command and returns the standard output, or fails.

func ExecOpts added in v14.5.0

func ExecOpts(t testing.TB, cfg config.Cfg, execCfg ExecConfig, args ...string) []byte

ExecOpts runs a git command with the given configuration.

func GetGitPackfileDirSize

func GetGitPackfileDirSize(t testing.TB, repoPath string) int64

GetGitPackfileDirSize gets the number of 1k blocks of a git object directory

func GetReplicaPath added in v14.9.0

func GetReplicaPath(ctx context.Context, t testing.TB, cfg config.Cfg, repo repository.GitRepo) string

GetReplicaPath retrieves the repository's replica path if the test has been run with Praefect in front of it. This is necessary if the test creates a repository through Praefect and peeks into the filesystem afterwards. Conn should be pointing to Praefect.

func HTTPServer added in v14.7.0

func HTTPServer(ctx context.Context, t testing.TB, gitCmdFactory git.CommandFactory, repoPath string, middleware func(http.ResponseWriter, *http.Request, http.Handler)) (int, func() error)

HTTPServer starts an HTTP server with git-http-backend(1) as CGI handler. The repository is prepared such that git-http-backend(1) will serve it by creating the "git-daemon-export-ok" magic file.

func InitRepo added in v14.2.0

func InitRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...InitRepoOpts) (*gitalypb.Repository, string)

InitRepo creates a new empty repository in the given storage. You can either pass no or exactly one InitRepoOpts.

func InitRepoDir

func InitRepoDir(t testing.TB, storagePath, relativePath string) *gitalypb.Repository

InitRepoDir creates a temporary directory for a repo, without initializing it

func NewCommand added in v14.7.0

func NewCommand(t testing.TB, cfg config.Cfg, args ...string) *exec.Cmd

NewCommand creates a new Git command ready for execution.

func NewCommandFactory added in v14.7.0

func NewCommandFactory(tb testing.TB, cfg config.Cfg, opts ...git.ExecCommandFactoryOption) git.CommandFactory

NewCommandFactory creates a new Git command factory.

func NewObjectPoolName

func NewObjectPoolName(t testing.TB) string

NewObjectPoolName returns a random pool repository name in format '@pools/[0-9a-z]{2}/[0-9a-z]{2}/[0-9a-z]{64}.git'.

func NewProtocolDetectingCommandFactory added in v14.8.0

func NewProtocolDetectingCommandFactory(ctx context.Context, t testing.TB, cfg config.Cfg) (git.CommandFactory, func() string)

NewProtocolDetectingCommandFactory creates a new intercepting Git command factory that allows the protocol to be tested. It returns this factory and a function to read the GIT_PROTOCOL environment variable created by the wrapper script.

func NewRepositoryName

func NewRepositoryName(t testing.TB, bare bool) string

NewRepositoryName returns a random repository hash in format '@hashed/[0-9a-f]{2}/[0-9a-f]{2}/[0-9a-f]{64}(.git)?'.

func RemoteExists

func RemoteExists(t testing.TB, cfg config.Cfg, repoPath string, remoteName string) bool

RemoteExists tests if the repository at repoPath has a Git remote named remoteName.

func RequireObjectExists added in v14.7.0

func RequireObjectExists(t testing.TB, cfg config.Cfg, repoPath string, objectID git.ObjectID)

RequireObjectExists asserts that the given repository does contain an object with the specified object ID.

func RequireObjectNotExists added in v14.7.0

func RequireObjectNotExists(t testing.TB, cfg config.Cfg, repoPath string, objectID git.ObjectID)

RequireObjectNotExists asserts that the given repository does not contain an object with the specified object ID.

func RequireTree

func RequireTree(t testing.TB, cfg config.Cfg, repoPath, treeish string, expectedEntries []TreeEntry)

RequireTree looks up the given treeish and asserts that its entries match the given expected entries. Tree entries are checked recursively.

func RewrittenRepository added in v14.9.0

func RewrittenRepository(ctx context.Context, t testing.TB, cfg config.Cfg, repository *gitalypb.Repository) *gitalypb.Repository

RewrittenRepository returns the repository as it would be received by a Gitaly after being rewritten by Praefect. This should be used when the repository is being accessed through the filesystem to ensure the access path is correct. If the test is not running with Praefect in front, it returns the an unaltered copy of repository.

func TestBitmapHasHashcache

func TestBitmapHasHashcache(t *testing.T, bitmap string)

TestBitmapHasHashcache checks if the named pack bitmap file contains "hash cache" data. See https://github.com/git/git/blob/master/Documentation/technical/bitmap-format.txt

func TestDeltaIslands

func TestDeltaIslands(t *testing.T, cfg config.Cfg, repoPath string, repack func() error)

TestDeltaIslands is based on the tests in https://github.com/git/git/blob/master/t/t5320-delta-islands.sh .

func TestRepository

func TestRepository(t *testing.T, cfg config.Cfg, getRepository GetRepositoryFunc)

TestRepository tests an implementation of Repository.

func WriteBlob

func WriteBlob(t testing.TB, cfg config.Cfg, testRepoPath string, contents []byte) git.ObjectID

WriteBlob writes the given contents as a blob into the repository and returns its OID.

func WriteBlobs

func WriteBlobs(t testing.TB, cfg config.Cfg, testRepoPath string, n int) []string

WriteBlobs writes n distinct blobs into the git repository's object database. Each object has the current time in nanoseconds as contents.

func WriteCheckNewObjectExistsHook

func WriteCheckNewObjectExistsHook(t testing.TB, repoPath string)

WriteCheckNewObjectExistsHook writes a pre-receive hook which only succeeds if it can find the object in the quarantine directory. if GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES were not passed through correctly to the hooks, it will fail

func WriteCommit

func WriteCommit(t testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCommitOption) git.ObjectID

WriteCommit writes a new commit into the target repository.

func WriteCustomHook

func WriteCustomHook(t testing.TB, repoPath, name string, content []byte) string

WriteCustomHook writes a hook in the repo/path.git/custom_hooks directory

func WriteEnvToCustomHook

func WriteEnvToCustomHook(t testing.TB, repoPath, hookName string) string

WriteEnvToCustomHook dumps the env vars that the custom hooks receives to a file

func WritePktlineDelim

func WritePktlineDelim(t *testing.T, writer io.Writer)

WritePktlineDelim writes the pktline-formatted delimiter into the writer.

func WritePktlineFlush

func WritePktlineFlush(t *testing.T, writer io.Writer)

WritePktlineFlush writes the pktline-formatted flush into the writer.

func WritePktlineString

func WritePktlineString(t *testing.T, writer io.Writer, data string)

WritePktlineString writes the pktline-formatted data into the writer.

func WriteRef added in v14.4.5

func WriteRef(t testing.TB, cfg config.Cfg, repoPath string, ref git.ReferenceName, oid git.ObjectID)

WriteRef writes a reference into the repository pointing to the given object ID.

func WriteTag added in v14.3.0

func WriteTag(
	t testing.TB,
	cfg config.Cfg,
	repoPath string,
	tagName string,
	targetRevision git.Revision,
	optionalConfig ...WriteTagConfig,
) git.ObjectID

WriteTag writes a new tag into the repository. This function either returns the tag ID in case an annotated tag was created, or otherwise the target object ID when a lightweight tag was created. Takes either no WriteTagConfig, in which case the default values will be used, or exactly one.

func WriteTree

func WriteTree(t testing.TB, cfg config.Cfg, repoPath string, entries []TreeEntry) git.ObjectID

WriteTree writes a new tree object to the given path. This function does not verify whether OIDs referred to by tree entries actually exist in the repository.

Types

type CloneRepoOpts added in v14.2.0

type CloneRepoOpts struct {
	// RelativePath determines the relative path of newly created Git repository. If unset, the
	// relative path is computed via NewRepositoryName.
	RelativePath string
	// WithWorktree determines whether the resulting Git repository should have a worktree or
	// not.
	WithWorktree bool
	// SourceRepo determines the name of the source repository which shall be cloned. The source
	// repository is assumed to be relative to "_build/testrepos". If unset, defaults to
	// "gitlab-test.git".
	SourceRepo string
}

CloneRepoOpts is an option for CloneRepo.

type CreateRepositoryConfig added in v14.8.0

type CreateRepositoryConfig struct {
	// ClientConn is the connection used to create the repository. If unset, the config is used to
	// dial the service.
	ClientConn *grpc.ClientConn
	// Storage determines the storage the repository is created in. If unset, the first storage
	// from the config is used.
	Storage config.Storage
	// RelativePath sets the relative path of the repository in the storage. If unset,
	// the relative path is set to a randomly generated hashed storage path
	RelativePath string
	// Seed determines which repository is used to seed the created repository. If unset, the repository
	// is just created. The value should be one of the test repositories in _build/testrepos.
	Seed string
}

CreateRepositoryConfig allows for configuring how the repository is created.

type ExecConfig added in v14.5.0

type ExecConfig struct {
	// Stdin sets up stdin of the spawned command.
	Stdin io.Reader
	// Stdout sets up stdout of the spawned command. Note that `ExecOpts()` will not return any
	// output anymore if this field is set.
	Stdout io.Writer
	// Env contains environment variables that should be appended to the spawned command's
	// environment.
	Env []string
}

ExecConfig contains configuration for ExecOpts.

type GetRepositoryFunc added in v14.8.0

type GetRepositoryFunc func(ctx context.Context, t testing.TB, seeded bool) (git.Repository, string)

GetRepositoryFunc is used to get a clean test repository for the different implementations of the Repository interface in the common test suite TestRepository.

type InitRepoOpts added in v14.2.0

type InitRepoOpts struct {
	// WithWorktree determines whether the resulting Git repository should have a worktree or
	// not.
	WithWorktree bool
	// WithRelativePath determines the relative path of this repository.
	WithRelativePath string
}

InitRepoOpts contains options for InitRepo.

type InterceptingCommandFactory added in v14.7.0

type InterceptingCommandFactory struct {
	// contains filtered or unexported fields
}

InterceptingCommandFactory is a git.CommandFactory which intercepts all executions of Git commands with a custom script.

func NewInterceptingCommandFactory added in v14.7.0

func NewInterceptingCommandFactory(
	ctx context.Context,
	tb testing.TB,
	cfg config.Cfg,
	generateScript func(git.ExecutionEnvironment) string,
	opts ...git.ExecCommandFactoryOption,
) *InterceptingCommandFactory

NewInterceptingCommandFactory creates a new command factory which intercepts Git commands. The given configuration must point to the real Git executable. The function will be executed to generate the script and receives as input the Git execution environment pointing to the real Git binary.

func (*InterceptingCommandFactory) GetExecutionEnvironment added in v14.7.0

func (f *InterceptingCommandFactory) GetExecutionEnvironment(ctx context.Context) git.ExecutionEnvironment

GetExecutionEnvironment returns the execution environment of the intercetping command factory. The Git binary path will point to the intercepting script, while environment variables will point to the intercepted Git installation.

func (*InterceptingCommandFactory) GitVersion added in v14.7.0

GitVersion returns the Git version as returned by the intercepted command.

func (*InterceptingCommandFactory) HooksPath added in v14.7.0

HooksPath returns the path where hooks are stored. This returns the actual hooks path of the real Git command factory.

func (*InterceptingCommandFactory) New added in v14.7.0

New creates a new Git command for the given repository using the intercepting script.

func (*InterceptingCommandFactory) NewWithDir added in v14.7.0

func (f *InterceptingCommandFactory) NewWithDir(ctx context.Context, dir string, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error)

NewWithDir creates a new Git command in the given directory using the intercepting script.

func (*InterceptingCommandFactory) NewWithoutRepo added in v14.7.0

func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error)

NewWithoutRepo creates a new Git command using the intercepting script.

type TreeEntry

type TreeEntry struct {
	// OID is the object ID the tree entry refers to.
	OID git.ObjectID
	// Mode is the file mode of the tree entry.
	Mode string
	// Path is the full path of the tree entry.
	Path string
	// Content is the content of the tree entry.
	Content string
}

TreeEntry represents an entry of a git tree object.

type WriteCommitOption

type WriteCommitOption func(*writeCommitConfig)

WriteCommitOption is an option which can be passed to WriteCommit.

func WithAlternateObjectDirectory added in v14.7.0

func WithAlternateObjectDirectory(alternateObjectDir string) WriteCommitOption

WithAlternateObjectDirectory will cause the commit to be written into the given alternate object directory. This can either be an absolute path or a relative path. In the latter case the path is considered to be relative to the repository path.

func WithBranch

func WithBranch(branch string) WriteCommitOption

WithBranch is an option for WriteCommit which will cause it to update the update the given branch name to the new commit.

func WithCommitterName added in v14.0.8

func WithCommitterName(name string) WriteCommitOption

WithCommitterName is an option for WriteCommit which will set the committer name.

func WithMessage

func WithMessage(message string) WriteCommitOption

WithMessage is an option for WriteCommit which will set the commit message.

func WithParents

func WithParents(parents ...git.ObjectID) WriteCommitOption

WithParents is an option for WriteCommit which will set the parent OIDs of the resulting commit.

func WithTreeEntries

func WithTreeEntries(entries ...TreeEntry) WriteCommitOption

WithTreeEntries is an option for WriteCommit which will cause it to create a new tree and use it as root tree of the resulting commit.

type WriteTagConfig added in v14.3.0

type WriteTagConfig struct {
	// Message is the message of an annotated tag. If left empty, then a lightweight tag will
	// be created.
	Message string
	// Force indicates whether existing tags with the same name shall be overwritten.
	Force bool
}

WriteTagConfig holds extra options for WriteTag.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL