gitwork

package
v0.0.0-...-d090e66 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LockFile is a flag that can be given to Repository.OpenFile. It locks the
	// file for writing. The file is unlocked when it is closed.
	LockFile = -1 << iota
)

Additional flags that can be given to Repository.OpenFile.

Variables

View Source
var DefaultAuthor = Author{
	Name:  "gitwork",
	Email: "gitwork@localhost",
}

DefaultAuthor is the default author used for making commits.

Functions

This section is empty.

Types

type Author

type Author struct {
	Name  string
	Email string
}

Author is the author used for making commits.

type CommitHash

type CommitHash = gitplumbing.Hash

CommitHash is the hash of the current commit.

type Pool

type Pool struct {
	Author    Author
	RootPath  string
	RemoteURL string
	// contains filtered or unexported fields
}

Pool helps manage a pool of git repositories.

func NewPool

func NewPool(rootPath, remoteURL string) (*Pool, error)

NewPool creates a new pool with the given store.

func (*Pool) Clone

func (p *Pool) Clone(ctx context.Context, shallow bool, dstDir string) (*PooledRepository, error)

Clone clones the repository at the given URL into the pool. If dstDir is empty, then a random directory is created. If dstDir already exists, then the repository is opened instead.

func (*Pool) Delete

func (p *Pool) Delete() error

Delete deletes all repositories that belong to the pool. Beware when calling this method.

func (*Pool) Open

func (p *Pool) Open(dir string) (*PooledRepository, error)

Open opens a repository in the pool. The given path is relative to the pool's root path.

type PooledRepository

type PooledRepository struct {
	*Repository
	// contains filtered or unexported fields
}

PooledRepository is a repository that belongs to a pool.

func (*PooledRepository) AbsPath

func (r *PooledRepository) AbsPath() string

AbsPath returns the absolute path to the repository in the pool.

func (*PooledRepository) Path

func (r *PooledRepository) Path() string

Path returns the path to the repository in the pool.

func (*PooledRepository) Pool

func (r *PooledRepository) Pool() *Pool

Pool returns the pool that the repository belongs to.

type Repository

type Repository struct {
	*git.Repository
	Config struct {
		Author Author
	}
}

Repository is a Git workspace. It mimics a regular Git repository.

func Clone

func Clone(ctx context.Context, url string, shallow bool, dst RepositoryStore) (*Repository, error)

Clone clones a repository into the workspace.

func Init

func Init(dst RepositoryStore) (*Repository, error)

Init initializes the workspace with nothing.

func Open

func Open(dst RepositoryStore) (*Repository, error)

Open opens an existing repository.

func (*Repository) Add

func (r *Repository) Add(path string) error

Add adds the given files to the index.

func (*Repository) AddAll

func (r *Repository) AddAll() error

AddAll adds all files to the index.

func (*Repository) Checkout

func (r *Repository) Checkout(ref string, create bool) error

Checkout checks out to the given ref.

func (*Repository) Commit

func (r *Repository) Commit(title, body string) (CommitHash, error)

Commit commits the changes in the repository. Changes must be added using Add.

func (*Repository) FS

func (r *Repository) FS() billy.Filesystem

FS returns the filesystem of the repository.

func (*Repository) OpenFile

func (r *Repository) OpenFile(path string, flag int) (*RepositoryFile, error)

EditFile edits or creates a file in the repository. f is called on the file once it's opened. The file is locked using flock while f is running.

func (*Repository) Push

func (r *Repository) Push(ctx context.Context, force bool) error

Push pushes the current branch to the remote.

func (*Repository) Worktree

func (r *Repository) Worktree() *git.Worktree

Worktree returns the worktree of the repository. It can be used to add and checkout files.

type RepositoryFile

type RepositoryFile struct {
	billy.File // treat the same as *os.File
	// contains filtered or unexported fields
}

RepositoryFile is a file in the repository.

func (*RepositoryFile) Close

func (r *RepositoryFile) Close() error

Close closes the file.

func (*RepositoryFile) Wipe

func (r *RepositoryFile) Wipe() error

Wipe wipes the content of the file.

type RepositoryStore

type RepositoryStore func() (billy.Filesystem, error)

func AtDir

func AtDir(path string) RepositoryStore

AtDir returns a RepositoryStore that creates a repository at the given directory.

func AtTempDir

func AtTempDir(dir string) RepositoryStore

AtTempDir returns a RepositoryStore that creates a repository at a temporary directory.

Jump to

Keyboard shortcuts

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