git

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: GPL-3.0 Imports: 36 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")
	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")
)
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")
)
View Source
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

func AddBookmark(cfg *config.Config, b *bookmark.Bookmark) error

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

func HasUnpulledCommits(ctx context.Context, repoPath string) (bool, error)

HasUnpulledCommits checks if there are commits on the upstream branch that have not yet been pulled locally.

func HasUpstream added in v0.1.30

func HasUpstream(ctx context.Context, repoPath string) error

HasUpstream checks whether the current branch has an upstream (remote tracking branch) configured.

func Import added in v0.1.16

func Import(a *app.Context, gm *Manager) ([]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, cfg *config.Git) (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 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 Remote added in v0.1.30

func Remote(ctx context.Context, repoPath string) (string, error)

Remote returns the origin of the repository.

func RemoveBookmarks added in v0.1.30

func RemoveBookmarks(cfg *config.Config, bs []*bookmark.Bookmark) error

func SetConfig added in v0.1.30

func SetConfig(ctx context.Context, c *config.Config)

SetConfig sets the app git config.

func SetUpstream added in v0.1.16

func SetUpstream(ctx context.Context, 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(path string) ([]string, error)

Tracked returns the currently tracked repositories.

func UpdateBookmark added in v0.1.30

func UpdateBookmark(cfg *config.Config, oldB, newB *bookmark.Bookmark) error

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

func WithCmd(cmd string) GitOptFn

WithCmd sets the Git command to use.

func WithContext added in v0.1.30

func WithContext(ctx context.Context) GitOptFn

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 NewManager added in v0.1.30

func NewManager(ctx context.Context, path string) (*Manager, error)

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, force bool) 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 PullResult added in v0.1.30

type PullResult struct {
	TotalBookmarks      int
	TotalReposProcessed int
	TotalSkipped        int
}

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.

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, force bool) (bool, error)

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

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

func (*RepositoryReader) Read added in v0.1.30

func (r *RepositoryReader) Read() ([]*bookmark.Bookmark, error)

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

func NewTracker(root string) *Tracker

NewTracker returns a new Tracker for the given root directory.

func (*Tracker) Contains added in v0.1.16

func (t *Tracker) Contains(name string) (bool, error)

Contains checks if a repository is tracked.

func (*Tracker) Load added in v0.1.16

func (t *Tracker) Load() error

Load loads the tracked repositories from the file (if exists).

func (*Tracker) Save added in v0.1.16

func (t *Tracker) Save() error

Save writes the tracked repositories to the file.

func (*Tracker) Sync added in v0.1.30

func (t *Tracker) Sync() error

Sync loads and then saves, ensuring file consistency.

func (*Tracker) Track added in v0.1.16

func (t *Tracker) Track(name string) error

Track adds a new repository to the tracker.

func (*Tracker) Untrack added in v0.1.16

func (t *Tracker) Untrack(name string) error

Untrack removes a repository from the tracker.

Jump to

Keyboard shortcuts

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