Documentation ¶
Index ¶
- Constants
- Variables
- func AuthProtocol(r *Remote) (p string, err error)
- func Less(ri, rj *Repository) bool
- func RandomString(n int) string
- func RevList(r *Repository, options RevListOptions) ([]*object.Commit, 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) Checkout(b *Branch) error
- 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) SetWorkStatus(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 RepositoryListener
- type RepositoryState
- type RevListOptions
- type StashedItem
- type TestHelper
- type WorkStatus
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" )
Variables ¶
var ( // Available implies repo is ready for the operation Available = WorkStatus{Status: 0, Ready: true} // Queued means repo is queued for a operation Queued = WorkStatus{Status: 1, Ready: false} // Working means an operation is just started for this repository Working = WorkStatus{Status: 2, Ready: false} // Paused is expected when a user interaction is required Paused = WorkStatus{Status: 3, Ready: true} // Success is the expected outcome of the operation Success = WorkStatus{Status: 4, Ready: true} // Fail is the unexpected outcome of the operation Fail = WorkStatus{Status: 5, Ready: false} )
Functions ¶
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 RandomString ¶
RandomString generates a random string of n length
func RevList ¶
func RevList(r *Repository, options RevListOptions) ([]*object.Commit, error)
RevList is the legacy implementation of "git rev-list" command.
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) InitializeCommits ¶
func (b *Branch) InitializeCommits(r *Repository) error
InitializeCommits loads the commits
type Commit ¶
type Commit struct { Hash string Author *Contributor Commiter *Contributor Message string Time string CommitType CommitType C *object.Commit }
Commit is the lightweight version of go-git's Reference struct. it holds hash of the commit, author's e-mail address, Message (subject and body combined) commit date and commit type whether it is local commit or a remote
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 LastModified sorting function
func (CommitTime) Less ¶
func (s CommitTime) Less(i, j int) bool
Less is the interface implementation for LastModified sorting function
func (CommitTime) Swap ¶
func (s CommitTime) Swap(i, j int)
Swap is the interface implementation for LastModified 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) 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) 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.
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) SetWorkStatus ¶
func (r *Repository) SetWorkStatus(ws WorkStatus)
SetWorkStatus sets the state of repository and sends repository updated event
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 ¶
type RepositoryEvent struct { Name string Data interface{} }
RepositoryEvent is used to transfer event-related data. It is passed to listeners when Publish() is called
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 // 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 TestHelper ¶
type TestHelper struct { Repository *Repository RepoPath string }
func InitTestRepository ¶
func InitTestRepository(t *testing.T) *TestHelper
func InitTestRepositoryFromLocal ¶
func InitTestRepositoryFromLocal(t *testing.T) *TestHelper
func (*TestHelper) BasicRepoPath ¶
func (h *TestHelper) BasicRepoPath() string
func (*TestHelper) CleanUp ¶
func (h *TestHelper) CleanUp(t *testing.T)
func (*TestHelper) DirtyRepoPath ¶
func (h *TestHelper) DirtyRepoPath() string
func (*TestHelper) NonRepoPath ¶
func (h *TestHelper) NonRepoPath() string
type WorkStatus ¶
WorkStatus is the state of the repository for an operation