git

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const MaxCommits = 200

MaxCommits is the maximum number of commits to load for the UI

Variables

View Source
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

func AcquireGitSemaphore(ctx context.Context) error

AcquireGitSemaphore acquires a token from the global git semaphore. This allows external packages to respect the concurrency limit for git operations.

func CompareNamesInsensitive added in v0.9.6

func CompareNamesInsensitive(a, b string) int

CompareNamesInsensitive compares two strings case-insensitively, with case-sensitive tiebreaking for equal lowercase runes. Returns -1 if a < b, 0 if a == b, 1 if a > b.

func NormalizeGitErrorMessage added in v0.9.2

func NormalizeGitErrorMessage(msg string) string

NormalizeGitErrorMessage trims git error noise so it can be shown in the UI.

func RandomString

func RandomString(n int) string

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 SetTraceLogging added in v0.9.2

func SetTraceLogging(enabled bool) error

SetTraceLogging enables or disables trace logging across repositories. When enabled a gitbatch.log file is created in the current working directory.

func UpstreamBranchName added in v0.9.6

func UpstreamBranchName(r *Repository) string

UpstreamBranchName returns the branch name portion of the upstream reference, or falls back to the current branch name. This is used when constructing pull/push reference arguments.

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

func (b *Branch) HasIncomingCommits() bool

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

func (b *Branch) PullableCount() (int, bool)

PullableCount returns the number of commits available to pull along with an indicator specifying whether the count could be determined.

type BranchState

type BranchState struct {
	Commit *Commit
}

BranchState hold the ref commit

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

func (*Commit) String

func (c *Commit) String() string

type CommitTime

type CommitTime []*object.Commit

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

type Contributor struct {
	Name  string
	Email string
	When  time.Time
}

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

type RemoteBranch struct {
	Name      string
	Reference *plumbing.Reference
}

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 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) 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) String

func (r *Repository) String() string

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{}
	Context context.Context
}

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
	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

type WorkStatus

type WorkStatus struct {
	Status uint8
	Ready  bool
}

WorkStatus is the state of the repository for an operation

type WorkTreeStatus added in v0.9.3

type WorkTreeStatus struct {
	Clean        bool
	HasConflicts bool
}

WorkTreeStatus represents the status of the working tree

Jump to

Keyboard shortcuts

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