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 Clone(destRepoPath, repoURL string) error
- func Config(c *config.AppConfig)
- func Import(c *ui.Console, gm *Manager, urlRepo string) ([]string, error)
- func Info(c *ui.Console, dbPath string) (string, error)
- func IsInitialized(repoPath string) bool
- func Read(c *ui.Console, path string) ([]*bookmark.Bookmark, error)
- func SetUpstream(repoPath string) error
- func StatusRepo(c *ui.Console, dbPath string) (string, error)
- func Tracked(trackerFile string) ([]string, error)
- type ClientInfo
- type GitOptFn
- type GitOpts
- type Location
- type Manager
- func (gm *Manager) AddAll() error
- func (gm *Manager) AddRemote(repoURL string) 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 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) Read(c *ui.Console) ([]*bookmark.Bookmark, error)
- 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() (*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) (bool, error)
- 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") ErrGitNoRemote = errors.New("git: no upstream configured") 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") )
Functions ¶
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 SetUpstream ¶ added in v0.1.16
SetUpstream sets the upstream for the current branch.
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 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 (*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 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) Read ¶ added in v0.1.16
Read reads and decrypts the repository's bookmarks, handling encryption if configured.
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() (*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 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 { List []string // List holds the paths of the tracked repositories. Filename string // Filename is the path to the file where the tracker data is stored. // contains filtered or unexported fields }
Tracker manages a list of tracked repositories stored in a file.