Documentation
¶
Overview ¶
Package git provides high-level utilities to initialize, manage, and interact with the bookmark's Git repositorie.
Package git provides the model and logic of a bookmarks Git repository.
Index ¶
- Constants
- Variables
- func AddBookmark(cfg *config.Config, b *bookmark.Bookmark) error
- func HasUnpulledCommits(ctx context.Context, repoPath string) (bool, error)
- func HasUpstream(ctx context.Context, repoPath string) error
- func Import(a *app.Context, gm *Manager) ([]string, error)
- func Info(c *ui.Console, dbPath string, cfg *config.Git) (string, error)
- func IsInitialized(repoPath string) bool
- func ReadRepo(ctx context.Context, root string, st *bookio.RepositoryLoader, ...) ([]*bookmark.Bookmark, error)
- func Remote(ctx context.Context, repoPath string) (string, error)
- func RemoveBookmarks(cfg *config.Config, bs []*bookmark.Bookmark) error
- func SetConfig(ctx context.Context, c *config.Config)
- func SetUpstream(ctx context.Context, repoPath string) error
- func StatusRepo(c *ui.Console, dbPath string) (string, error)
- func Tracked(path string) ([]string, error)
- func UpdateBookmark(cfg *config.Config, oldB, newB *bookmark.Bookmark) error
- func UpdateSummaryAndCommit(gr *Repository, version string) error
- type ClientInfo
- type GitOptFn
- type GitOpts
- type Location
- type Manager
- func (gm *Manager) AddAll() error
- func (gm *Manager) AddRemote(repoURL string, force bool) error
- func (gm *Manager) Clone(repoURL string) error
- func (gm *Manager) Commit(msg string) error
- func (gm *Manager) Exec(commands ...string) error
- func (gm *Manager) HasUnpushedCommits() (bool, error)
- func (gm *Manager) Init(force bool) error
- func (gm *Manager) IsInitialized() bool
- func (gm *Manager) Push() error
- func (gm *Manager) Remote() (string, error)
- func (gm *Manager) SetRepoPath(repoPath string)
- type PullResult
- type RepoProcessor
- type RepoProcessorOption
- type RepoProcessorOptions
- type Repository
- func (gr *Repository) Add(bs []*bookmark.Bookmark) error
- func (gr *Repository) AskForEncryption(c *ui.Console) error
- func (gr *Repository) Commit(msg string) error
- func (gr *Repository) Drop(mesg string) error
- func (gr *Repository) Export() error
- func (gr *Repository) IsEncrypted() bool
- func (gr *Repository) IsTracked() bool
- func (gr *Repository) Records() ([]*bookmark.Bookmark, error)
- func (gr *Repository) Remove(bs []*bookmark.Bookmark) error
- func (gr *Repository) RepoStatsWrite() error
- func (gr *Repository) Stats() (*SyncGitSummary, error)
- func (gr *Repository) Status(c *ui.Console) string
- func (gr *Repository) String() string
- func (gr *Repository) Summary() (*SyncGitSummary, error)
- func (gr *Repository) SummaryUpdate(version string) (*SyncGitSummary, error)
- func (gr *Repository) Track() error
- func (gr *Repository) Untrack(mesg string) error
- func (gr *Repository) UpdateOne(oldB, newB *bookmark.Bookmark) error
- func (gr *Repository) Write(bs []*bookmark.Bookmark, force bool) (bool, error)
- type RepositoryReader
- type RepositoryReaderOptFn
- type RepositoryReaderOpts
- type SyncGitSummary
- type Tracker
Constants ¶
const (
AttributesFile = ".gitattributes"
)
const JSONFileExt = ".json"
const SummaryFileName = "summary.json"
Variables ¶
var ( ErrGitInitialized = errors.New("git: is initialized") ErrGitNotInitialized = errors.New("git: is not initialized") ErrGitNoCommits = errors.New("git: no commits found") ErrGitNoUpstream = errors.New("git: no upstream configured") ErrGitUpstreamExists = errors.New("git: remote origin already exists") ErrGitNothingToCommit = errors.New("git: nothing to commit, working tree clean") ErrGitUpToDate = errors.New("git: everything up-to-date") ErrGitRepoNotFound = errors.New("git: repo not found") ErrGitRepoURLEmpty = errors.New("git: repo url is empty") )
var ( ErrNoManager = errors.New("manager is required") ErrNoRepoPath = errors.New("repoPath is required") ErrNoDBPath = errors.New("database path is required") )
var ( ErrGitTracked = errors.New("git: repo already tracked") ErrGitNotTracked = errors.New("git: repo not tracked") ErrGitNoRepos = errors.New("git: no repos found") ErrGitTrackNotLoaded = errors.New("git: tracker not loaded") ErrGitRepoNameEmpty = errors.New("git: repo name is empty") ErrGitCurrentRepo = errors.New("git: current repo not set") )
var GPGStrategy = &bookio.RepositoryLoader{ LoaderFn: gpgLoader, Prefix: "Decrypting GPG bookmarks", FileFilter: bookio.And( bookio.IsFile, bookio.HasExtension(gpg.Extension), bookio.NotNamed(SummaryFileName), ), }
Functions ¶
func AddBookmark ¶ added in v0.1.30
AddBookmark adds a bookmark to Git version control if the repository is tracked. Stages the bookmark, updates repository statistics, and creates a commit.
func HasUnpulledCommits ¶ added in v0.1.30
HasUnpulledCommits checks if there are commits on the upstream branch that have not yet been pulled locally.
func HasUpstream ¶ added in v0.1.30
HasUpstream checks whether the current branch has an upstream (remote tracking branch) configured.
func Import ¶ added in v0.1.16
Import clones a Git repository, parses its bookmark files, and imports them into the application.
func IsInitialized ¶
IsInitialized checks if the repo is initialized.
func ReadRepo ¶ added in v0.1.30
func ReadRepo( ctx context.Context, root string, st *bookio.RepositoryLoader, sp *rotato.Rotato, ) ([]*bookmark.Bookmark, error)
ReadRepo is the unified function that uses the Strategy Pattern. It accepts a specific RepositoryLoader to delegate file loading and filtering.
func RemoveBookmarks ¶ added in v0.1.30
func SetUpstream ¶ added in v0.1.16
SetUpstream sets the upstream for the current branch.
func UpdateBookmark ¶ added in v0.1.30
UpdateBookmark updates a bookmark in Git version control. Only proceeds if Git repository is initialized and tracking the database.
func UpdateSummaryAndCommit ¶ added in v0.1.30
func UpdateSummaryAndCommit(gr *Repository, version string) error
Types ¶
type ClientInfo ¶
type ClientInfo struct {
Hostname string `json:"hostname"` // Hostname is the client's hostname.
Platform string `json:"platform"` // Platform is the client's operating system platform.
Architect string `json:"architecture"` // Architect is the client's system architecture.
AppVersion string `json:"app_version"` // AppVersion is the application's version.
}
ClientInfo holds information about the client machine and application.
type GitOptFn ¶ added in v0.1.16
type GitOptFn func(*GitOpts)
func WithContext ¶ added in v0.1.30
type Location ¶ added in v0.1.16
type Location struct {
Name string // Database name without extension (e.g., "bookmarks")
DBName string // Database base name (e.g., "main.db")
DBPath string // Database fullpath (e.g., "/home/user/.local/share/app/main.db")
Git string // Path to where to store the Git repository (e.g., "~/.local/share/gomarks/git")
Path string // Path to where to store the associated Git files (e.g., "~/.local/share/gomarks/git/bookmarks")
Hash string // Hash of the database fullpath (for internal lookups/storage)
}
Location holds all path and naming information for a repository.
type Manager ¶ added in v0.1.16
Manager represents a Git repository manager.
func NewManager ¶ added in v0.1.30
func (*Manager) HasUnpushedCommits ¶ added in v0.1.16
HasUnpushedCommits checks if there are any unpushed commits in the repo.
func (*Manager) IsInitialized ¶ added in v0.1.16
IsInitialized returns true if the Git repository is initialized.
func (*Manager) SetRepoPath ¶ added in v0.1.16
SetRepoPath sets the repository path.
type PullResult ¶ added in v0.1.30
PullResult tracks the results of a pull operation.
type RepoProcessor ¶ added in v0.1.30
type RepoProcessor struct {
Console *ui.Console
Root string
DestPath string
Repos []string
*RepoProcessorOptions
// contains filtered or unexported fields
}
RepoProcessor handles the processing of a single repository.
func NewRepoProcessor ¶ added in v0.1.30
func NewRepoProcessor(c *ui.Console, g *Manager, a *config.Config, opts ...RepoProcessorOption) *RepoProcessor
func (*RepoProcessor) Pull ¶ added in v0.1.30
func (rp *RepoProcessor) Pull() error
Pull pulls bookmarks from remote git repository and replicate the repositories as databases.
type RepoProcessorOption ¶ added in v0.1.30
type RepoProcessorOption func(*RepoProcessorOptions)
func WithRPContext ¶ added in v0.1.30
func WithRPContext(ctx context.Context) RepoProcessorOption
type RepoProcessorOptions ¶ added in v0.1.30
type RepoProcessorOptions struct {
// contains filtered or unexported fields
}
type Repository ¶ added in v0.1.16
type Repository struct {
Loc *Location // Encapsulates all path and naming details
Tracker *Tracker // Git repo tracker
Git *Manager // Git manager
}
Repository represents a bookmarks repository.
func NewRepo ¶ added in v0.1.16
func NewRepo(dbPath string) (*Repository, error)
func (*Repository) Add ¶ added in v0.1.16
func (gr *Repository) Add(bs []*bookmark.Bookmark) error
Add adds the bookmarks to the repo.
func (*Repository) AskForEncryption ¶ added in v0.1.16
func (gr *Repository) AskForEncryption(c *ui.Console) error
AskForEncryption prompts the user to enable GPG encryption for the repository if it's not already encrypted.
func (*Repository) Commit ¶ added in v0.1.16
func (gr *Repository) Commit(msg string) error
Commit commits the bookmarks to the git repo.
func (*Repository) Drop ¶ added in v0.1.16
func (gr *Repository) Drop(mesg string) error
Drop removes a repository's files, updates its summary, and commits the changes.
func (*Repository) Export ¶ added in v0.1.16
func (gr *Repository) Export() error
Export exports the repository's bookmarks to Git, handling encryption if configured.
func (*Repository) IsEncrypted ¶ added in v0.1.16
func (gr *Repository) IsEncrypted() bool
IsEncrypted returns whether the repo is encrypted.
func (*Repository) IsTracked ¶ added in v0.1.16
func (gr *Repository) IsTracked() bool
IsTracked returns whether the repo is tracked.
func (*Repository) Records ¶ added in v0.1.16
func (gr *Repository) Records() ([]*bookmark.Bookmark, error)
Records retrieves all bookmarks from the repository's database.
func (*Repository) Remove ¶ added in v0.1.16
func (gr *Repository) Remove(bs []*bookmark.Bookmark) error
Remove removes the bookmarks from the repo.
func (*Repository) RepoStatsWrite ¶ added in v0.1.16
func (gr *Repository) RepoStatsWrite() error
RepoStatsWrite calculates, updates, and saves the repository's statistics to its summary file.
func (*Repository) Stats ¶ added in v0.1.16
func (gr *Repository) Stats() (*SyncGitSummary, error)
Stats returns the repo stats.
func (*Repository) Status ¶ added in v0.1.16
func (gr *Repository) Status(c *ui.Console) string
Status returns a prettify status of the repository.
func (*Repository) String ¶ added in v0.1.16
func (gr *Repository) String() string
String returns the repo summary.
func (*Repository) Summary ¶ added in v0.1.16
func (gr *Repository) Summary() (*SyncGitSummary, error)
Summary returns the repo summary.
func (*Repository) SummaryUpdate ¶ added in v0.1.16
func (gr *Repository) SummaryUpdate(version string) (*SyncGitSummary, error)
SummaryUpdate returns a new SyncGitSummary.
func (*Repository) Track ¶ added in v0.1.16
func (gr *Repository) Track() error
Track tracks a repository in Git, exporting its data and committing the changes.
func (*Repository) Untrack ¶ added in v0.1.16
func (gr *Repository) Untrack(mesg string) error
Untrack untracks a repository in Git, removes its files, and commits the change.
type RepositoryReader ¶ added in v0.1.30
type RepositoryReader struct {
RepositoryReaderOpts
Root string
Path string
}
func NewReader ¶ added in v0.1.30
func NewReader(repoPath string, opts ...RepositoryReaderOptFn) *RepositoryReader
type RepositoryReaderOptFn ¶ added in v0.1.30
type RepositoryReaderOptFn func(*RepositoryReaderOpts)
func WithRepositoryReaderContext ¶ added in v0.1.30
func WithRepositoryReaderContext(ctx context.Context) RepositoryReaderOptFn
func WithRepositoryReaderSpinner ¶ added in v0.1.30
func WithRepositoryReaderSpinner(sp *rotato.Rotato) RepositoryReaderOptFn
type RepositoryReaderOpts ¶ added in v0.1.30
type RepositoryReaderOpts struct {
// contains filtered or unexported fields
}
type SyncGitSummary ¶
type SyncGitSummary struct {
GitBranch string `json:"git_branch"` // GitBranch is the current Git branch.
GitRemote string `json:"git_remote"` // GitRemote is the Git remote URL.
LastSync string `json:"last_sync"` // LastSync is the timestamp of the last sync.
ConflictResolution string `json:"conflict_resolution"` // Describes the strategy for resolving conflicts.
HashAlgorithm string `json:"hash_algorithm"` // Specifies the algorithm used for checksums.
RepoStats *dbtask.RepoStats `json:"stats"` // RepoStats contains statistics for the repository.
ClientInfo *ClientInfo `json:"client_info"` // ClientInfo contains details about the client.
Checksum string `json:"checksum"` // Checksum is the summary's generated checksum.
}
SyncGitSummary summarizes the state and metadata of a Git-synced repository.
func NewSummary ¶
func NewSummary() *SyncGitSummary
func (*SyncGitSummary) GenChecksum ¶ added in v0.1.16
func (s *SyncGitSummary) GenChecksum()
GenChecksum generates a checksum for the SyncGitSummary.
type Tracker ¶ added in v0.1.16
type Tracker struct {
Repos []string // Repos holds tracked repository names or paths.
Filename string // Filename is the path to the JSON file.
// contains filtered or unexported fields
}
Tracker manages a list of tracked repositories stored in a file.
func NewTracker ¶ added in v0.1.16
NewTracker returns a new Tracker for the given root directory.
func (*Tracker) Load ¶ added in v0.1.16
Load loads the tracked repositories from the file (if exists).