git

package
v1.15.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBinaryFile        = errors.New("binary file")
	ErrNotBinaryFile     = errors.New("not binary file")
	ErrMissingGitModules = errors.New("no .gitmodules file found")
	ErrInvalidGitModules = errors.New("invalid .gitmodules file")
	ErrNotSubmodule      = errors.New("path is not a submodule")
)
View Source
var (
	TerminateWalk error = errors.New("terminate walk")
)

Functions

func Fork

func Fork(repoPath, source string, cfg *knotconfig.Config) error

func ForkWithSandbox

func ForkWithSandbox(repoPath, source string, cfg *knotconfig.Config, sb sandbox.Backend) error

ForkWithSandbox clones source into repoPath, optionally wrapping the post-clone configure step in sb. The initial clone itself is not sandboxed because the target directory doesn't exist yet when the ruleset is applied.

func InitBare

func InitBare(path, defaultBranch string) error

Types

type BranchesOptions

type BranchesOptions struct {
	Limit  int
	Offset int
}

type CommitCount

type CommitCount struct {
	ByEmail map[string]int
}

type ConflictInfo

type ConflictInfo struct {
	Filename string
	Reason   string
}

type ErrMerge

type ErrMerge struct {
	Message     string
	Conflicts   []ConflictInfo
	HasConflict bool
	OtherError  error
}

func (ErrMerge) Error

func (e ErrMerge) Error() string

type GitRepo

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

func Open

func Open(path string, ref string) (*GitRepo, error)

func PlainOpen

func PlainOpen(path string) (*GitRepo, error)

func (*GitRepo) AnalyzeLanguages

func (g *GitRepo) AnalyzeLanguages(ctx context.Context) (LangBreakdown, error)

func (*GitRepo) Branch

func (g *GitRepo) Branch(name string) (*plumbing.Reference, error)

func (*GitRepo) Branches

func (g *GitRepo) Branches(opts *BranchesOptions) ([]types.Branch, error)

func (*GitRepo) ChangedFilesBetween

func (g *GitRepo) ChangedFilesBetween(oldSha, newSha string) ([]string, error)

ChangedFilesBetween returns the list of files changed between oldSha and newSha. If oldSha is the zero hash (initial push), all files in newSha are returned.

func (*GitRepo) Commit

func (g *GitRepo) Commit(h plumbing.Hash) (*object.Commit, error)

func (*GitRepo) Commits

func (g *GitRepo) Commits(offset, limit int) ([]*object.Commit, error)

func (*GitRepo) DeleteBranch

func (g *GitRepo) DeleteBranch(branch string) error

func (*GitRepo) Diff

func (g *GitRepo) Diff() (*types.NiceDiff, error)

func (*GitRepo) DiffTree

func (g *GitRepo) DiffTree(commit1, commit2 *object.Commit) (*types.DiffTree, error)

func (*GitRepo) File

func (g *GitRepo) File(path string) (*object.File, error)

func (*GitRepo) FileContentN

func (g *GitRepo) FileContentN(path string, cap int64) ([]byte, error)

func (*GitRepo) FileTree

func (g *GitRepo) FileTree(ctx context.Context, path string) ([]types.NiceTree, error)

func (*GitRepo) FindMainBranch

func (g *GitRepo) FindMainBranch() (string, error)

func (*GitRepo) FormatPatch

func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, []types.FormatPatch, error)

func (*GitRepo) Hash

func (g *GitRepo) Hash() plumbing.Hash

func (*GitRepo) LastCommitFile

func (g *GitRepo) LastCommitFile(ctx context.Context, filePath string) (*types.LastCommitInfo, error)

LastCommitFile returns the last commit information for a specific file path

func (*GitRepo) MergeBase

func (g *GitRepo) MergeBase(a, b *object.Commit) (*object.Commit, error)

func (*GitRepo) MergeCheckWithOptions

func (g *GitRepo) MergeCheckWithOptions(patchData string, targetBranch string, mo MergeOptions) error

func (*GitRepo) MergeWithOptions

func (g *GitRepo) MergeWithOptions(patchData string, targetBranch string, opts MergeOptions) error

func (*GitRepo) RawContent

func (g *GitRepo) RawContent(path string) ([]byte, error)

func (*GitRepo) RefUpdateMeta

func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) (RefUpdateMeta, error)

func (*GitRepo) Refresh

func (g *GitRepo) Refresh() error

re-open a repository and update references

func (*GitRepo) Remote

func (g *GitRepo) Remote() (string, error)

func (*GitRepo) ResolveRevision

func (g *GitRepo) ResolveRevision(revStr string) (*object.Commit, error)

func (*GitRepo) SetDefaultBranch

func (g *GitRepo) SetDefaultBranch(branch string) error

func (*GitRepo) Submodule

func (g *GitRepo) Submodule(path string) (*config.Submodule, error)

func (*GitRepo) Submodules

func (g *GitRepo) Submodules() (*config.Modules, error)

read and parse .gitmodules

func (*GitRepo) Sync

func (g *GitRepo) Sync() error

func (*GitRepo) Tags

func (g *GitRepo) Tags(opts *TagsOptions) ([]object.Tag, error)

func (*GitRepo) TotalCommits

func (g *GitRepo) TotalCommits() (int, error)

func (*GitRepo) TrackHiddenRemoteRef

func (g *GitRepo) TrackHiddenRemoteRef(forkRef, remoteRef string) error

TrackHiddenRemoteRef tracks a hidden remote in the repository. For example, if the feature branch on the fork (forkRef) is feature-1, and the remoteRef, i.e. the branch we want to merge into, is main, this will result in a refspec:

+refs/heads/main:refs/hidden/feature-1/main

func (*GitRepo) Walk

func (g *GitRepo) Walk(
	ctx context.Context,
	root string,
	cb callback,
) error

func (*GitRepo) WithSandbox

func (g *GitRepo) WithSandbox(sb sandbox.Backend) *GitRepo

WithSandbox returns a copy of the GitRepo that uses the given sandbox backend for all git subprocesses.

func (*GitRepo) WriteArchive

func (g *GitRepo) WriteArchive(w io.Writer, format string, prefix string) error

func (*GitRepo) WriteTar

func (g *GitRepo) WriteTar(w io.Writer, prefix string) error

WriteTar writes itself from a tree into a binary tar file format. prefix is root folder to be appended.

type LangBreakdown

type LangBreakdown map[string]int64

type MergeCheckCache

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

func (*MergeCheckCache) Get

func (m *MergeCheckCache) Get(g *GitRepo, patch string, targetBranch string) (error, bool)

func (*MergeCheckCache) Set

func (m *MergeCheckCache) Set(g *GitRepo, patch string, targetBranch string, mergeCheck error)

type MergeOptions

type MergeOptions struct {
	CommitMessage  string
	CommitBody     string
	AuthorName     string
	AuthorEmail    string
	CommitterName  string
	CommitterEmail string
	FormatPatch    bool
}

MergeOptions specifies the configuration for a merge operation

type PostReceiveLine

type PostReceiveLine struct {
	OldSha plumbing.Hash // old sha of reference being updated
	NewSha plumbing.Hash // new sha of reference being updated
	Ref    string        // the reference being updated
}

func ParsePostReceive

func ParsePostReceive(buf io.Reader) ([]PostReceiveLine, error)

type RefUpdateMeta

type RefUpdateMeta struct {
	CommitCount   CommitCount
	IsDefaultRef  bool
	LangBreakdown LangBreakdown
}

func (RefUpdateMeta) AsRecord

type RepoSuite

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

func NewRepoSuite

func NewRepoSuite(t *testing.T) *RepoSuite

type TagsOptions

type TagsOptions struct {
	Limit   int
	Offset  int
	Pattern string
}

Source Files

  • branch.go
  • cmd.go
  • diff.go
  • fork.go
  • git.go
  • language.go
  • last_commit.go
  • merge.go
  • post_receive.go
  • repo.go
  • tag.go
  • test_common.go
  • tree.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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