Documentation ¶
Index ¶
- Constants
- Variables
- type Author
- type CommitHash
- type Pool
- type PooledRepository
- type Repository
- func (r *Repository) Add(path string) error
- func (r *Repository) AddAll() error
- func (r *Repository) Checkout(ref string, create bool) error
- func (r *Repository) Commit(title, body string) (CommitHash, error)
- func (r *Repository) FS() billy.Filesystem
- func (r *Repository) OpenFile(path string, flag int) (*RepositoryFile, error)
- func (r *Repository) Push(ctx context.Context, force bool) error
- func (r *Repository) Worktree() *git.Worktree
- type RepositoryFile
- type RepositoryStore
Constants ¶
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 ¶
var DefaultAuthor = Author{
Name: "gitwork",
Email: "gitwork@localhost",
}
DefaultAuthor is the default author used for making commits.
Functions ¶
This section is empty.
Types ¶
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 (*Pool) Clone ¶
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.
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 (*Repository) Add ¶
func (r *Repository) Add(path string) error
Add adds the given 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) 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.