git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package git provides access to git repositories.

Example
if err := fixtures.Init(); err != nil {
	panic(err)
}
defer fixtures.Clean()

fixture := fixtures.Basic().One()
fs := fixture.DotGit()
storer, err := filesystem.NewStorage(fs)
if err != nil {
	panic(err)
}

// Create the git service with a repository loader that allows it to find
// a repository by ID.
srv := NewService(&StorerCommitLoader{storer})
changes, err := srv.GetChanges(context.Background(),
	&lookout.ChangesRequest{
		Base: &lookout.ReferencePointer{
			InternalRepositoryURL: "file:///myrepo",
			Hash:                  "af2d6a6954d532f8ffb47615169c8fdf9d383a1a",
		},
		Head: &lookout.ReferencePointer{
			InternalRepositoryURL: "file:///myrepo",
			Hash:                  "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
		},
	})
if err != nil {
	panic(err)
}

for changes.Next() {
	change := changes.Change()
	fmt.Printf("changed: %s\n", change.Head.Path)
}

if err := changes.Err(); err != nil {
	panic(err)
}

if err := changes.Close(); err != nil {
	panic(err)
}
Output:

changed: go/example.go
changed: php/crappy.php
changed: vendor/foo.go

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrRepositoryExists    = errors.NewKind("repository %s already exists")
	ErrRepositoryNotExists = errors.NewKind("repository %s not exists")
)

Functions

func NewChangeBlobScanner

func NewChangeBlobScanner(scanner lookout.ChangeScanner, base, head *object.Tree) *lookout.FnChangeScanner

NewChangeBlobScanner creates new FnChangeScanner

func NewChangeExcludeVendorScanner

func NewChangeExcludeVendorScanner(scanner lookout.ChangeScanner) *lookout.FnChangeScanner

NewChangeExcludeVendorScanner creates new FnChangeScanner

func NewChangeFilterScanner

func NewChangeFilterScanner(scanner lookout.ChangeScanner, include, exclude string) *lookout.FnChangeScanner

NewChangeFilterScanner creates new FnChangeScanner

func NewFileBlobScanner

func NewFileBlobScanner(scanner lookout.FileScanner, tree *object.Tree) *lookout.FnFileScanner

NewFileBlobScanner creates new FnFileScanner

func NewFileExcludeVendorScanner

func NewFileExcludeVendorScanner(scanner lookout.FileScanner) *lookout.FnFileScanner

NewFileExcludeVendorScanner creates new FnFileScanner

func NewFileFilterScanner

func NewFileFilterScanner(scanner lookout.FileScanner, include, exclude string) *lookout.FnFileScanner

NewFileFilterScanner creates new FnFileScanner

Types

type CommitLoader

type CommitLoader interface {
	LoadCommits(context.Context, ...lookout.ReferencePointer) (
		[]*object.Commit, error)
}

type DiffTreeScanner

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

DiffTreeScanner is a scanner for files of diff between git trees

func NewDiffTreeScanner

func NewDiffTreeScanner(base, head *object.Tree) *DiffTreeScanner

NewDiffTreeScanner creates new DiffTreeScanner

func (*DiffTreeScanner) Change

func (s *DiffTreeScanner) Change() *lookout.Change

func (*DiffTreeScanner) Close

func (s *DiffTreeScanner) Close() error

func (*DiffTreeScanner) Err

func (s *DiffTreeScanner) Err() error

func (*DiffTreeScanner) Next

func (s *DiffTreeScanner) Next() bool

type Library

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

Library controls the persistence of multiple git repositories.

func NewLibrary

func NewLibrary(fs billy.Filesystem) *Library

NewLibrary creates a new Library based on the given filesystem.

func (*Library) Get

func (l *Library) Get(url *lookout.RepositoryInfo) (*git.Repository, error)

Get get the requested repository based on the given URL.

func (*Library) GetOrInit

func (l *Library) GetOrInit(url *lookout.RepositoryInfo) (
	*git.Repository, error)

GetOrInit get the requested repository based on the given URL, or inits a new repository.

func (*Library) Has

func (l *Library) Has(url *lookout.RepositoryInfo) (bool, error)

Has returns true if a repository with the given URL exists.

func (*Library) Init

func (l *Library) Init(url *lookout.RepositoryInfo) (*git.Repository, error)

Init inits a new repository for the given URL.

type LibraryCommitLoader

type LibraryCommitLoader struct {
	Library *Library
	Syncer  *Syncer
}

func NewLibraryCommitLoader

func NewLibraryCommitLoader(l *Library, s *Syncer) *LibraryCommitLoader

func (*LibraryCommitLoader) LoadCommits

func (l *LibraryCommitLoader) LoadCommits(
	ctx context.Context, rps ...lookout.ReferencePointer) (
	[]*object.Commit, error)

type Service

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

Service implements data service interface on top of go-git

func NewService

func NewService(loader CommitLoader) *Service

NewService creates new git Service

func (*Service) GetChanges

func (r *Service) GetChanges(ctx context.Context, req *lookout.ChangesRequest) (
	lookout.ChangeScanner, error)

GetChanges returns a ChangeScanner that scans all changes according to the request.

func (*Service) GetFiles

func (r *Service) GetFiles(ctx context.Context, req *lookout.FilesRequest) (
	lookout.FileScanner, error)

GetFiles returns a FilesScanner that scans all files according to the request.

type StorerCommitLoader

type StorerCommitLoader struct {
	Storer storer.Storer
}

func NewStorerCommitLoader

func NewStorerCommitLoader(storer storer.Storer) *StorerCommitLoader

func (*StorerCommitLoader) LoadCommits

func (l *StorerCommitLoader) LoadCommits(ctx context.Context,
	rps ...lookout.ReferencePointer) ([]*object.Commit, error)

type Syncer

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

Syncer syncs the local copy of git repository for a given CommitRevision.

func NewSyncer

func NewSyncer(l *Library) *Syncer

NewSyncer returns a Syncer for the given Library.

func (*Syncer) Sync

func (s *Syncer) Sync(ctx context.Context,
	rps ...lookout.ReferencePointer) error

Sync syncs the local git repository to the given reference pointers.

type TreeScanner

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

TreeScanner is a scanner for files of git tree

func NewTreeScanner

func NewTreeScanner(tree *object.Tree) *TreeScanner

NewTreeScanner creates new TreeScanner

func (*TreeScanner) Change

func (s *TreeScanner) Change() *lookout.Change

func (*TreeScanner) Close

func (s *TreeScanner) Close() error

func (*TreeScanner) Err

func (s *TreeScanner) Err() error

func (*TreeScanner) File

func (s *TreeScanner) File() *lookout.File

func (*TreeScanner) Next

func (s *TreeScanner) Next() bool

Jump to

Keyboard shortcuts

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