mem_git

package
v0.0.0-...-d625583 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// These are the commit hashes generated by CommitN(2) when run as the
	// first call to MemGit.
	Commit0 = "407108ae8039ba9dce77e81057721fc7c4dbab87"
	Commit1 = "a1dcf4a9669ff77919dfca71901ec98145b0af94"
)

Variables

View Source
var (
	// BaseTime is an arbitrary timestamp used as the time of the first
	// commit. Subsequent commits add a fixed duration to the timestamp
	// of their parent(s). This keeps the commit hashes predictable.
	BaseTime = time.Unix(1571926390, 0).UTC()
)

Functions

func FakeCommit

func FakeCommit(t sktest.TestingT, msg, branch string, parents ...*vcsinfo.LongCommit) *vcsinfo.LongCommit

FakeCommit creates a LongCommit with the given message, belonging to the given branch, and with the given parent commits. Its Timestamp and Index increase monotonically with respect to the parents.

func FakeCommitAt

func FakeCommitAt(t sktest.TestingT, msg, branch string, ts time.Time, parents ...*vcsinfo.LongCommit) *vcsinfo.LongCommit

FakeCommitAt creates a LongCommit with the given message at the given time, belonging to the given branch, and with the given parent commits. Its Index increases monotonically with respect to the parents.

func FillWithBranchingHistory

func FillWithBranchingHistory(mg *MemGit) []string

FillWithBranchingHistory adds commits to the MemGit.

The repo layout looks like this:

older newer c0--c1------c3--c4--

\-c2-----/

Returns the commit hashes in order from c0-c4. This is analogous to git_builder.FillWithBranchingHistory.

Types

type MemGit

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

MemGit is a struct used for writing fake commits into a GitStore.

func New

New returns a MemGit instance which writes to the given GitStore.

func (*MemGit) AddUpdater

func (g *MemGit) AddUpdater(u Updater)

AddUpdater adds the given Updater to the MemGit. Subsequent mutations to the MemGit will result in a call to Updater.Update().

func (*MemGit) CheckoutBranch

func (g *MemGit) CheckoutBranch(branch string)

CheckoutBranch switches to the given branch.

func (*MemGit) Commit

func (g *MemGit) Commit(msg string, parents ...string) string

Commit adds a commit to the GitStore with the given commit message and parents, and returns its hash. If no parents are provided, the head of the current branch is used as the parent. In either case, the head of the current branch is set to be the new commit.

func (*MemGit) CommitAt

func (g *MemGit) CommitAt(msg string, ts time.Time, parents ...string) string

CommitAt adds a commit to the GitStore with the given commit message, timestamp, and parents, and returns its hash. If no parents are provided, the head of the current branch is used as the parent. In either case, the head of the current branch is set to be the new commit.

func (*MemGit) CommitN

func (g *MemGit) CommitN(n int) []string

CommitN adds N commits to the GitStore on the current branch and returns their hashes in reverse chronological order.

func (*MemGit) Merge

func (g *MemGit) Merge(branch string) string

Merge creates a new commit which merges the given branch into the currently active branch.

func (*MemGit) NewBranch

func (g *MemGit) NewBranch(branch, head string)

NewBranch creates the given branch at the given commit hash and switches to it.

type Updater

type Updater interface {
	// Update indicates that the MemGit has changed. The Context passed to
	// Update is likely to be a placeholder or empty.
	Update(ctx context.Context) error
}

Updater is an interface used for automatically receiving updates when the MemGit changes.

Jump to

Keyboard shortcuts

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