gitutil

package
v0.0.0-...-2ad639e Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 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 error is git.ErrNoMergeBase.

func IsErrRevisionNotExist

func IsErrRevisionNotExist(err error) bool

IsErrRevisionNotExist returns true if the error is git.ErrRevisionNotExist.

func IsErrSubmoduleNotExist

func IsErrSubmoduleNotExist(err error) bool

IsErrSubmoduleNotExist returns true if the 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) ListTagsAfter

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

func (*MockModuleStore) PullRequestMeta

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

func (*MockModuleStore) RepoAddRemote

func (m *MockModuleStore) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error

func (*MockModuleStore) RepoDiffNameOnly

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

func (*MockModuleStore) RepoLog

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

func (*MockModuleStore) RepoMergeBase

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

func (*MockModuleStore) RepoRemoveRemote

func (m *MockModuleStore) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error

func (*MockModuleStore) RepoTags

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

type ModuleStore

type ModuleStore interface {
	// AddRemote adds a new remote to the repository in given path.
	RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error
	// RepoDiffNameOnly returns a list of changed files between base and head revisions
	// of the repository in given path.
	RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
	// RepoLog 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.
	RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
	// RepoMergeBase returns merge base between base and head revisions of the repository
	// in given path.
	RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
	// RepoRemoveRemote removes a remote from the repository in given path.
	RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error
	// RepoTags returns a list of tags of the repository in given path.
	RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)

	// GetPullRequestMeta 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.

NOTE: All methods are sorted in alphabetical order.

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