Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireGitSemaphore(ctx context.Context) error
- func AuthProtocol(r *Remote) (p string, err error)
- func Less(ri, rj *Repository) bool
- func NormalizeGitErrorMessage(msg string) string
- func RandomString(n int) string
- func RegisterRepositoryHook(h RepositoryHook)
- func ReleaseGitSemaphore()
- func RevList(r *Repository, options RevListOptions) ([]*object.Commit, error)
- func RevListCount(r *Repository, options RevListOptions) (int, error)
- func SetTraceLogging(enabled bool) error
- type Alphabetical
- type Branch
- type BranchState
- type Commit
- type CommitTime
- type CommitType
- type Contributor
- type Credentials
- type File
- type FileStatus
- type FilesAlphabetical
- type LastModified
- type Reference
- type Remote
- type RemoteBranch
- type Repository
- func (r *Repository) ApplyOperationError(err error) error
- func (r *Repository) Checkout(b *Branch) error
- func (r *Repository) GetWorkTreeStatus() (WorkTreeStatus, error)
- func (r *Repository) MarkClean()
- func (r *Repository) MarkCriticalError(message string)
- func (r *Repository) MarkDisabled()
- func (r *Repository) MarkFailure(message string, recoverable bool)
- func (r *Repository) MarkRecoverableError(message string)
- func (r *Repository) MarkRequiresCredentials(message string)
- func (r *Repository) NotifyRepositoryUpdated()
- func (r *Repository) On(event string, listener RepositoryListener)
- func (r *Repository) Publish(eventName string, data interface{}) error
- func (r *Repository) Refresh() error
- func (r *Repository) RefreshModTime() time.Time
- func (r *Repository) RequestRefresh() error
- func (r *Repository) SetWorkStatus(ws WorkStatus)
- func (r *Repository) SetWorkStatusSilent(ws WorkStatus)
- func (r *Repository) Stash() (string, error)
- func (r *Repository) String() string
- func (r *Repository) SyncRemoteAndBranch(b *Branch) error
- func (r *Repository) WorkStatus() WorkStatus
- type RepositoryEvent
- type RepositoryHook
- type RepositoryListener
- type RepositoryState
- type RevListOptions
- type StashedItem
- type WorkStatus
- type WorkTreeStatus
Constants ¶
const ( AuthProtocolHTTP = "http" AuthProtocolHTTPS = "https" AuthProtocolSSH = "ssh" )
Schemes for authentication
const ( // RepositoryUpdated defines the topic for an updated repository. RepositoryUpdated = "repository.updated" // BranchUpdated defines the topic for an updated branch. BranchUpdated = "branch.updated" // RepositoryRefreshRequested signals that a repository should reload its metadata. RepositoryRefreshRequested = "repository.refresh.requested" // RepositoryEvaluationRequested signals that a repository's state should be re-evaluated. RepositoryEvaluationRequested = "repository.evaluation.requested" // RepositoryGitCommandRequested schedules execution of a git command on the git queue. RepositoryGitCommandRequested = "repository.git.command.requested" // RepositoryEventTraced is an internal event used to route trace logging messages. RepositoryEventTraced = "repository.event.traced" )
const MaxCommits = 200
MaxCommits is the maximum number of commits to load for the UI
Variables ¶
var ( // Available implies repo is ready for the operation Available = WorkStatus{Status: 0, Ready: true} // Pending indicates repo is waiting for an operation to start Pending = WorkStatus{Status: 1, Ready: false} // Queued means repo is queued for a operation Queued = WorkStatus{Status: 2, Ready: false} // Working means an operation is just started for this repository Working = WorkStatus{Status: 3, Ready: false} // Paused is expected when a user interaction is required Paused = WorkStatus{Status: 4, Ready: true} // Success is the expected outcome of the operation Success = WorkStatus{Status: 5, Ready: true} // Fail is the unexpected outcome of the operation Fail = WorkStatus{Status: 6, Ready: false} )
Functions ¶
func AcquireGitSemaphore ¶ added in v0.9.3
AcquireGitSemaphore acquires a token from the global git semaphore. This allows external packages to respect the concurrency limit for git operations.
func AuthProtocol ¶
AuthProtocol returns the type of protocol for given remote's URL various auth protocols require different kind of authentication
func Less ¶
func Less(ri, rj *Repository) bool
Less returns a comparison between to repositories by name
func NormalizeGitErrorMessage ¶ added in v0.9.2
NormalizeGitErrorMessage trims git error noise so it can be shown in the UI.
func RandomString ¶
RandomString generates a random string of n length
func RegisterRepositoryHook ¶ added in v0.9.2
func RegisterRepositoryHook(h RepositoryHook)
RegisterRepositoryHook registers a hook that will run whenever a repository is created.
func ReleaseGitSemaphore ¶ added in v0.9.3
func ReleaseGitSemaphore()
ReleaseGitSemaphore releases a token to the global git semaphore.
func RevList ¶
func RevList(r *Repository, options RevListOptions) ([]*object.Commit, error)
RevList is the legacy implementation of "git rev-list" command.
func RevListCount ¶ added in v0.8.0
func RevListCount(r *Repository, options RevListOptions) (int, error)
RevListCount returns the count of commits between two references. This is more efficient than RevList when you only need the count.
func SetTraceLogging ¶ added in v0.9.2
SetTraceLogging enables or disables trace logging across repositories. When enabled a gitbatch.log file is created in the current working directory.
Types ¶
type Alphabetical ¶
type Alphabetical []*Repository
Alphabetical slice is the re-ordered *Repository slice that sorted according to alphabetical order (A-Z)
func (Alphabetical) Len ¶
func (s Alphabetical) Len() int
Len is the interface implementation for Alphabetical sorting function
func (Alphabetical) Less ¶
func (s Alphabetical) Less(i, j int) bool
Less is the interface implementation for Alphabetical sorting function
func (Alphabetical) Swap ¶
func (s Alphabetical) Swap(i, j int)
Swap is the interface implementation for Alphabetical sorting function
type Branch ¶
type Branch struct {
Name string
Reference *plumbing.Reference
Upstream *RemoteBranch
Commits []*Commit
State *BranchState
Pushables string
Pullables string
Clean bool
}
Branch is the wrapper of go-git's Reference struct. In addition to that, it also holds name of the branch, pullable and pushable commit count from the branchs' upstream. It also tracks if the repository has unstaged or uncommit- ed changes
func (*Branch) HasIncomingCommits ¶ added in v0.9.1
HasIncomingCommits reports whether the branch has pullable commits from its upstream.
func (*Branch) InitializeCommits ¶
func (b *Branch) InitializeCommits(r *Repository) error
InitializeCommits loads the commits
func (*Branch) PullableCount ¶ added in v0.9.1
PullableCount returns the number of commits available to pull along with an indicator specifying whether the count could be determined.
type Commit ¶
type Commit struct {
Hash string
Author *Contributor
Commiter *Contributor
Message string
Time string
CommitType CommitType
C *object.Commit
}
Commit is the wrapper for "object.Commit" and holds the commit type
type CommitTime ¶
CommitTime slice is the re-ordered *object.Commit slice that sorted according commit date
func (CommitTime) Len ¶
func (s CommitTime) Len() int
Len is the interface implementation for CommitTime sorting function
func (CommitTime) Less ¶
func (s CommitTime) Less(i, j int) bool
Less is the interface implementation for CommitTime sorting function
func (CommitTime) Swap ¶
func (s CommitTime) Swap(i, j int)
Swap is the interface implementation for CommitTime sorting function
type CommitType ¶
type CommitType string
CommitType is the Type of the commit; it can be local or remote (upstream diff)
const ( // LocalCommit is the commit that not pushed to remote branch LocalCommit CommitType = "local" // EvenCommit is the commit that recorded locally EvenCommit CommitType = "even" // RemoteCommit is the commit that not merged to local branch RemoteCommit CommitType = "remote" )
type Contributor ¶
Contributor is the person
type Credentials ¶
type Credentials struct {
// User is the user id for authentication
User string
// Password is the secret information required for authentication
Password string
}
Credentials holds user credentials to authenticate and authorize while communicating with remote if required
type File ¶
type File struct {
Name string
AbsPath string
X FileStatus
Y FileStatus
}
File represents the status of a file in an index or work tree
type FileStatus ¶
type FileStatus byte
FileStatus is the short representation of state of a file
const ( // StatusNotupdated says file not updated StatusNotupdated FileStatus = ' ' // StatusModified says file is modifed StatusModified FileStatus = 'M' // StatusModifiedUntracked says file is modifed and un-tracked StatusModifiedUntracked FileStatus = 'm' // StatusAdded says file is added to index StatusAdded FileStatus = 'A' // StatusDeleted says file is deleted StatusDeleted FileStatus = 'D' // StatusRenamed says file is renamed StatusRenamed FileStatus = 'R' // StatusCopied says file is copied StatusCopied FileStatus = 'C' // StatusUpdated says file is updated StatusUpdated FileStatus = 'U' // StatusUntracked says file is untraced StatusUntracked FileStatus = '?' // StatusIgnored says file is ignored StatusIgnored FileStatus = '!' )
type FilesAlphabetical ¶
type FilesAlphabetical []*File
FilesAlphabetical slice is the re-ordered *File slice that sorted according to alphabetical order (A-Z)
func (FilesAlphabetical) Len ¶
func (s FilesAlphabetical) Len() int
Len is the interface implementation for Alphabetical sorting function
func (FilesAlphabetical) Less ¶
func (s FilesAlphabetical) Less(i, j int) bool
Less is the interface implementation for Alphabetical sorting function
func (FilesAlphabetical) Swap ¶
func (s FilesAlphabetical) Swap(i, j int)
Swap is the interface implementation for Alphabetical sorting function
type LastModified ¶
type LastModified []*Repository
LastModified slice is the re-ordered *Repository slice that sorted according to last modified date of the repository directory
func (LastModified) Len ¶
func (s LastModified) Len() int
Len is the interface implementation for LastModified sorting function
func (LastModified) Less ¶
func (s LastModified) Less(i, j int) bool
Less is the interface implementation for LastModified sorting function
func (LastModified) Swap ¶
func (s LastModified) Swap(i, j int)
Swap is the interface implementation for LastModified sorting function
type Remote ¶
type Remote struct {
Name string
URL []string
RefSpecs []string
Branches []*RemoteBranch
}
Remote struct is simply a collection of remote branches and wraps it with the name of the remote and fetch/push urls. It also holds the *selected* remote branch
type RemoteBranch ¶
RemoteBranch is the wrapper of go-git's Reference struct. In addition to that, it also holds name of the remote branch
type Repository ¶
type Repository struct {
RepoID string
Name string
AbsPath string
ModTime time.Time
Repo git.Repository
Branches []*Branch
Remotes []*Remote
Stasheds []*StashedItem
State *RepositoryState
// contains filtered or unexported fields
}
Repository is the main entity of the application. The repository name is actually the name of its folder in the host's filesystem. It holds the go-git repository entity along with critic entities such as remote/branches and commits
func Create ¶
func Create(dir string) (*Repository, error)
func FastInitializeRepo ¶
func FastInitializeRepo(dir string) (r *Repository, err error)
FastInitializeRepo initializes a Repository struct without its belongings.
func InitializeRepo ¶
func InitializeRepo(dir string) (r *Repository, err error)
InitializeRepo initializes a Repository struct with its belongings.
func (*Repository) ApplyOperationError ¶ added in v0.9.2
func (r *Repository) ApplyOperationError(err error) error
ApplyOperationError normalises an error from a git command and assigns the corresponding repository state.
func (*Repository) Checkout ¶
func (r *Repository) Checkout(b *Branch) error
Checkout to given branch. If any errors occur, the method returns it instead of returning nil
func (*Repository) GetWorkTreeStatus ¶ added in v0.9.3
func (r *Repository) GetWorkTreeStatus() (WorkTreeStatus, error)
GetWorkTreeStatus checks the working tree status using git status --porcelain. It returns whether the tree is clean and if there are any conflicts.
func (*Repository) MarkClean ¶ added in v0.9.2
func (r *Repository) MarkClean()
MarkClean updates the current branch as clean.
func (*Repository) MarkCriticalError ¶ added in v0.9.2
func (r *Repository) MarkCriticalError(message string)
MarkCriticalError transitions the repository into a critical error state.
func (*Repository) MarkDisabled ¶ added in v0.9.3
func (r *Repository) MarkDisabled()
MarkDisabled marks the current branch as having unmerged or unpushed work. This reflects the repository entering a disabled state until reconciled or refreshed.
func (*Repository) MarkFailure ¶ added in v0.9.2
func (r *Repository) MarkFailure(message string, recoverable bool)
MarkFailure is preserved for backward compatibility. Prefer using MarkCriticalError or MarkRecoverableError for clarity.
func (*Repository) MarkRecoverableError ¶ added in v0.9.2
func (r *Repository) MarkRecoverableError(message string)
MarkRecoverableError transitions the repository into a recoverable error state.
func (*Repository) MarkRequiresCredentials ¶ added in v0.9.3
func (r *Repository) MarkRequiresCredentials(message string)
MarkRequiresCredentials transitions the repository into a state requiring credentials.
func (*Repository) NotifyRepositoryUpdated ¶ added in v0.9.2
func (r *Repository) NotifyRepositoryUpdated()
NotifyRepositoryUpdated emits a repository.updated event without mutating state.
func (*Repository) On ¶
func (r *Repository) On(event string, listener RepositoryListener)
On adds new listener. listener is a callback function that will be called when event emits
func (*Repository) Publish ¶
func (r *Repository) Publish(eventName string, data interface{}) error
Publish publishes the data to a certain event by its name. Events are either queued for async dispatch or handled synchronously.
func (*Repository) Refresh ¶
func (r *Repository) Refresh() error
Refresh the belongings of a repository, this function is called right after fetch/pull/merge operations
func (*Repository) RefreshModTime ¶ added in v0.9.3
func (r *Repository) RefreshModTime() time.Time
RefreshModTime updates the repository's modification time by checking critical git files. It returns the latest modification time found.
func (*Repository) RequestRefresh ¶ added in v0.9.2
func (r *Repository) RequestRefresh() error
RequestRefresh schedules a metadata refresh via the repository's event queue.
func (*Repository) SetWorkStatus ¶
func (r *Repository) SetWorkStatus(ws WorkStatus)
SetWorkStatus sets the state of repository and sends repository updated event
func (*Repository) SetWorkStatusSilent ¶ added in v0.9.2
func (r *Repository) SetWorkStatusSilent(ws WorkStatus)
SetWorkStatusSilent sets the state of repository without triggering a notification. Use this for UI-only state changes (like tagging) that don't reflect actual repository changes.
func (*Repository) Stash ¶
func (r *Repository) Stash() (string, error)
Stash is the wrapper of conventional "git stash" command
func (*Repository) String ¶
func (r *Repository) String() string
func (*Repository) SyncRemoteAndBranch ¶
func (r *Repository) SyncRemoteAndBranch(b *Branch) error
SyncRemoteAndBranch synchronizes remote branch with current branch
func (*Repository) WorkStatus ¶
func (r *Repository) WorkStatus() WorkStatus
WorkStatus returns the state of the repository such as queued, failed etc.
type RepositoryEvent ¶
RepositoryEvent is used to transfer event-related data. It is passed to listeners when Publish() is called
type RepositoryHook ¶ added in v0.9.2
type RepositoryHook func(*Repository)
RepositoryHook represents a function that is executed after a repository has been initialized.
type RepositoryListener ¶
type RepositoryListener func(event *RepositoryEvent) error
RepositoryListener is a type for listeners
type RepositoryState ¶
type RepositoryState struct {
Branch *Branch
Remote *Remote
Message string
RecoverableError bool
RequiresCredentials bool
// contains filtered or unexported fields
}
RepositoryState is the current pointers of a repository
type RevListOptions ¶
type RevListOptions struct {
// Ref1 is the first reference hash to link
Ref1 string
// Ref2 is the second reference hash to link
Ref2 string
}
RevListOptions defines the rules of rev-list func
type StashedItem ¶
type StashedItem struct {
StashID int
BranchName string
Hash string
Description string
EntityPath string
}
StashedItem holds the required fields for a stashed change
func (*StashedItem) Pop ¶
func (stashedItem *StashedItem) Pop() (string, error)
Pop is the wrapper of "git stash pop" command that used for a file
func (*StashedItem) Show ¶
func (stashedItem *StashedItem) Show() (string, error)
Show is the wrapper of "git stash show -p " command
type WorkStatus ¶
WorkStatus is the state of the repository for an operation
type WorkTreeStatus ¶ added in v0.9.3
WorkTreeStatus represents the status of the working tree