git

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: GPL-3.0 Imports: 37 Imported by: 0

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

View Source
const (
	AttributesFile = ".gitattributes"
)
View Source
const JSONFileExt = ".json"
View Source
const SummaryFileName = "summary.json"

Variables

View Source
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")
)
View Source
var (
	ErrNoManager  = errors.New("manager is required")
	ErrNoRepoPath = errors.New("repoPath is required")
	ErrNoDBPath   = errors.New("database path is required")
)
View Source
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 Clone

func Clone(destRepoPath, repoURL string) error

func Config added in v0.1.16

func Config(c *config.AppConfig)

Config sets the app git config.

func Import added in v0.1.16

func Import(c *ui.Console, gm *Manager, urlRepo string) ([]string, error)

Import clones a Git repository, parses its bookmark files, and imports them into the application.

func Info added in v0.1.16

func Info(c *ui.Console, dbPath string) (string, error)

Info returns a prettify info of the repository.

func IsInitialized

func IsInitialized(repoPath string) bool

IsInitialized checks if the repo is initialized.

func Read added in v0.1.16

func Read(c *ui.Console, path string) ([]*bookmark.Bookmark, error)

Read reads the repo and returns the bookmarks.

func SetUpstream added in v0.1.16

func SetUpstream(repoPath string) error

SetUpstream sets the upstream for the current branch.

func StatusRepo added in v0.1.16

func StatusRepo(c *ui.Console, dbPath string) (string, error)

func Tracked added in v0.1.16

func Tracked(trackerFile string) ([]string, error)

Tracked returns the tracked repositories.

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 WithCmd added in v0.1.16

func WithCmd(cmd string) GitOptFn

WithCmd sets the Git command to use.

type GitOpts added in v0.1.16

type GitOpts struct {
	// contains filtered or unexported fields
}

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

type Manager struct {
	GitOpts
	RepoPath string
	// contains filtered or unexported fields
}

Manager represents a Git repository manager.

func NewGit added in v0.1.16

func NewGit(repoPath string, opts ...GitOptFn) *Manager

NewGit creates a new GitManager.

func (*Manager) AddAll added in v0.1.16

func (gm *Manager) AddAll() error

AddAll adds all local changes.

func (*Manager) AddRemote added in v0.1.16

func (gm *Manager) AddRemote(repoURL string) error

AddRemote adds a remote repository.

func (*Manager) Clone added in v0.1.16

func (gm *Manager) Clone(repoURL string) error

Clone clones a repository.

func (*Manager) Commit added in v0.1.16

func (gm *Manager) Commit(msg string) error

Commit commits changes to the repository.

func (*Manager) Exec added in v0.1.16

func (gm *Manager) Exec(commands ...string) error

Exec executes a command in the repository.

func (*Manager) HasUnpushedCommits added in v0.1.16

func (gm *Manager) HasUnpushedCommits() (bool, error)

HasUnpushedCommits checks if there are any unpushed commits in the repo.

func (*Manager) Init added in v0.1.16

func (gm *Manager) Init(force bool) error

Init creates a new Git repository.

func (*Manager) IsInitialized added in v0.1.16

func (gm *Manager) IsInitialized() bool

IsInitialized returns true if the Git repository is initialized.

func (*Manager) Push added in v0.1.16

func (gm *Manager) Push() error

Push pushes changes to the remote repository.

func (*Manager) Remote added in v0.1.16

func (gm *Manager) Remote() (string, error)

Remote returns the origin of the repository.

func (*Manager) SetRepoPath added in v0.1.16

func (gm *Manager) SetRepoPath(repoPath string)

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

func (gr *Repository) Read(c *ui.Console) ([]*bookmark.Bookmark, error)

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.

func (*Repository) UpdateOne added in v0.1.16

func (gr *Repository) UpdateOne(oldB, newB *bookmark.Bookmark) error

UpdateOne updates the bookmarks in the repo.

func (*Repository) Write added in v0.1.16

func (gr *Repository) Write(bs []*bookmark.Bookmark) (bool, error)

Write exports the provided bookmarks to the repository's file, encrypting if configured.

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.

func NewTracker added in v0.1.16

func NewTracker(root string) *Tracker

func (*Tracker) Contains added in v0.1.16

func (t *Tracker) Contains(s string) bool

Contains returns true if the repo is tracked.

func (*Tracker) Load added in v0.1.16

func (t *Tracker) Load() error

Load loads the repositories from the tracker file.

func (*Tracker) Save added in v0.1.16

func (t *Tracker) Save() error

Save saves the tracker.

func (*Tracker) Track added in v0.1.16

func (t *Tracker) Track(s string) *Tracker

Track adds the repo to the tracker.

func (*Tracker) Untrack added in v0.1.16

func (t *Tracker) Untrack(s string) *Tracker

Untrack removes the repo from the tracker.

Jump to

Keyboard shortcuts

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