gitutil

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferSubmoduleURL

func InferSubmoduleURL(baseURL string, mod *git.Submodule) string

InferSubmoduleURL returns the inferred external URL of the submodule at best effort. The `baseURL` should be the URL of the current repository. If the submodule URL looks like a relative path, it assumes that the submodule is another repository on the same Gogs instance by appending it to the `baseURL` with the commit.

func IsErrNoMergeBase

func IsErrNoMergeBase(err error) bool

IsErrNoMergeBase returns true if the underlying error is git.ErrNoMergeBase.

func IsErrRevisionNotExist

func IsErrRevisionNotExist(err error) bool

IsErrRevisionNotExist returns true if the underlying error is git.ErrRevisionNotExist.

func IsErrSubmoduleNotExist

func IsErrSubmoduleNotExist(err error) bool

IsErrSubmoduleNotExist returns true if the underlying error is git.ErrSubmoduleNotExist.

func NewError

func NewError(err error) error

NewError wraps given error.

func SetMockModuleStore

func SetMockModuleStore(t *testing.T, mock ModuleStore)

Types

type Diff

type Diff struct {
	*git.Diff
	Files []*DiffFile
}

Diff is a wrapper to git.Diff with helper methods.

func NewDiff

func NewDiff(oldDiff *git.Diff) *Diff

NewDiff returns a new wrapper of given git.Diff.

func ParseDiff

func ParseDiff(r io.Reader, maxFiles, maxFileLines, maxLineChars int) (*Diff, error)

ParseDiff parses the diff from given io.Reader.

func RepoDiff

func RepoDiff(repo *git.Repository, rev string, maxFiles, maxFileLines, maxLineChars int, opts ...git.DiffOptions) (*Diff, error)

RepoDiff parses the diff on given revisions of given repository.

type DiffFile

type DiffFile struct {
	*git.DiffFile
	Sections []*DiffSection
}

DiffFile is a wrapper to git.DiffFile with helper methods.

func (*DiffFile) HighlightClass

func (diffFile *DiffFile) HighlightClass() string

HighlightClass returns the detected highlight class for the file.

type DiffSection

type DiffSection struct {
	*git.DiffSection
	// contains filtered or unexported fields
}

DiffSection is a wrapper to git.DiffSection with helper methods.

func (*DiffSection) ComputedInlineDiffFor

func (s *DiffSection) ComputedInlineDiffFor(line *git.DiffLine) template.HTML

ComputedInlineDiffFor computes inline diff for the given line.

type Error

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

Error is a wrapper of a Git error, which handles not found.

func (Error) NotFound

func (e Error) NotFound() bool

type MockModuleStore

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

func (*MockModuleStore) DiffNameOnly added in v0.13.0

func (m *MockModuleStore) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)

func (*MockModuleStore) ListTagsAfter

func (m *MockModuleStore) ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)

func (*MockModuleStore) Log added in v0.13.0

func (m *MockModuleStore) Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)

func (*MockModuleStore) MergeBase added in v0.13.0

func (m *MockModuleStore) MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)

func (*MockModuleStore) PullRequestMeta

func (m *MockModuleStore) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)

func (*MockModuleStore) RemoteAdd added in v0.13.0

func (m *MockModuleStore) RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error

func (*MockModuleStore) RemoteRemove added in v0.13.0

func (m *MockModuleStore) RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error

func (*MockModuleStore) RepoTags

func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)

type ModuleStore

type ModuleStore interface {
	// RemoteAdd adds a new remote to the repository in given path.
	RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error
	// DiffNameOnly returns a list of changed files between base and head revisions
	// of the repository in given path.
	DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
	// Log returns a list of commits in the state of given revision of the
	// repository in given path. The returned list is in reverse chronological
	// order.
	Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
	// MergeBase returns merge base between base and head revisions of the
	// repository in given path.
	MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
	// RemoteRemove removes a remote from the repository in given path.
	RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error
	// RepoTags returns a list of tags of the repository in given path.
	RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)

	// PullRequestMeta gathers pull request metadata based on given head and base
	// information.
	PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
	// ListTagsAfter returns a list of tags "after" (exclusive) given tag.
	ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)
}

ModuleStore is the interface for Git operations.

var Module ModuleStore = module{}

Module is a mockable interface for Git operations.

type PullRequestMeta

type PullRequestMeta struct {
	// The merge base of the pull request.
	MergeBase string
	// The commits that are requested to be merged.
	Commits []*git.Commit
	// The number of files changed.
	NumFiles int
}

PullRequestMeta contains metadata for a pull request.

type TagsPage

type TagsPage struct {
	// List of tags in the current page.
	Tags []string
	// Whether the results include the latest tag.
	HasLatest bool
	// When results do not include the latest tag, an indicator of 'after' to go back.
	PreviousAfter string
	// Whether there are more tags in the next page.
	HasNext bool
}

TagsPage contains a list of tags and pagination information.

Jump to

Keyboard shortcuts

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