git

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(dir string, url string) <-chan *CloneUpdate

func Pull

func Pull(dir string) <-chan *PullUpdate

func RepoNameFromUrl

func RepoNameFromUrl(url string) string

func RevListCommitCount

func RevListCommitCount(dir string, fromCommitHash string, toCommitHash string) (int, error)

func RevParseShowTopLevel

func RevParseShowTopLevel(dir string) (string, error)

RevParseShowTopLevel returns absolute path of top level directory of Git repository. This command will return `/repo` if called from `/repo/subdir` if `/repo` is a Git repository.

Types

type CloneStatus

type CloneStatus string
const (
	Cloning           CloneStatus = "Cloning"
	Cloned            CloneStatus = "Cloned"
	BadRedirect       CloneStatus = "BadRedirect"
	CloneRepoNotFound CloneStatus = "RepositoryNotFound"
	AuthRequired      CloneStatus = "AuthRequired"
	CloneFailed       CloneStatus = "CloneFailed"
)

type CloneUpdate

type CloneUpdate struct {
	Status CloneStatus
	Error  string
}

type PullStatus

type PullStatus string
const (
	Pulling                PullStatus = "Pulling"
	Pulled                 PullStatus = "Pulled"
	CouldNotResolveHost    PullStatus = "CouldNotResolveHost"
	ConnectionFailure      PullStatus = "ConnectionFailure"
	OverwritesLocalChanges PullStatus = "OverwritesLocalChanges"
	MergeConflict          PullStatus = "MergeConflict"
	DetachedHead           PullStatus = "DetachedHead"
	PullRepoNotFound       PullStatus = "RepositoryNotFound"
	RemoteBranchNotFound   PullStatus = "RemoteBranchNotFound"
	UnsetUpstream          PullStatus = "UnsetUpstream"
	UnstagedChanges        PullStatus = "UnstagedChanges"
	NotRepository          PullStatus = "NotRepository"
	PullFailed             PullStatus = "PullFailed"
)

type PullUpdate

type PullUpdate struct {
	Status        PullStatus
	Error         string
	PulledCommits int
	RepoState     *RepoState
	StashList     []*StashedChangeset
}

type RemoteDetails

type RemoteDetails struct {
	// Url is the repo's git remote origin.
	Url string
}

RemoteDetails contains git program details for a Repository.

type RepoState

type RepoState struct {
	LocalCommits    int
	StagedChanges   int
	UnstagedChanges int
	UntrackedFiles  int
}

RepoState holds data from `git status` and is available with git.Status.

func Status

func Status(dir string) (*RepoState, error)

type Repository

type Repository struct {
	// Name is the display name for the Repository, and will be the path from the workspace root to the repository
	// directory when not explicitly set.
	Name string
	// Dir is the absolute path to the repository.
	Dir string
	// Git specific config for the repository remote such as RemoteDetails.Url.
	Git *RemoteDetails
}

Repository represents a cloned git repo within a Workspace. Instances for local repositories within a workspace can be instantiated with ScanForRepositories or NewWorkspace.

func NewRepository

func NewRepository(name string, dir string, url string) *Repository

NewRepository creates a Repository.

func ScanForRepositories

func ScanForRepositories(dir string, repoScanDepth int) []*Repository

ScanForRepositories will recursively look for git repositories within the specified directory. repoScanDepth controls how many directories deep the repository scan will recurse.

type StashedChangeset

type StashedChangeset struct {
	Description  string
	Name         string
	OnBranch     string
	OnCommitHash string
}

func StashList

func StashList(dir string) ([]*StashedChangeset, error)

type SyncOp

type SyncOp string
const (
	CloneSync SyncOp = "Clone"
	PullSync  SyncOp = "Pull"
)

type SyncOptions

type SyncOptions struct {
	DetailLocalChanges bool
}

type SyncStatus

type SyncStatus string
const (
	SyncSuccess SyncStatus = "SyncSuccess"
	SyncWarning SyncStatus = "SyncWarning"
	SyncFailure SyncStatus = "SyncFailure"
)

type SyncUpdate

type SyncUpdate struct {
	Repo    string
	Op      SyncOp
	Message string
	Error   string
	Status  SyncStatus
}

type Workspace

type Workspace struct {
	RootDir      string
	Repositories map[string]*Repository
}

Workspace represents a local directory structure of git repositories.

func NewWorkspace

func NewWorkspace(rootDir string, repositories []*Repository, repoScanDepth int) *Workspace

NewWorkspace creates a Workspace at a specified rootDir. Repositories will be configured with the repositories argument and using ScanForRepositories. Use repoScanDepth to specify how deep subdirectories should be scanned for additional repositories. repoScanDepth=0 skips subdirectory scanning.

func (*Workspace) Sync

func (w *Workspace) Sync(syncOptions *SyncOptions) <-chan *SyncUpdate

Sync performs clones and pulls to sync all Repository instances within a Workspace using the git.Clone and git.Pull APIs. A git clone will be performed for any repositories configured within the Workspace that are not present on disk. For Workspace repositories already cloned, the Sync operation will perform a git pull.

Jump to

Keyboard shortcuts

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