Documentation ¶
Overview ¶
Package dotfile provides functions and interfaces for dotfile operations.
Index ¶
- Variables
- func Alias(alias, path string) (string, error)
- func CheckAlias(alias string) error
- func CheckPath(path string) error
- func Checkout(r Reverter, hash string) error
- func Compress(uncompressed []byte) (*bytes.Buffer, error)
- func Diff(g Getter, hash1, hash2 string) (*gotextdiff.Unified, error)
- func Init(c Committer, path, alias string) error
- func IsClean(g Getter, hash string) (bool, error)
- func NewCommit(c Committer, message string) error
- func ShortenHash(hash string) string
- func Uncompress(compressed []byte) (*bytes.Buffer, error)
- func UncompressRevision(g Getter, hash string) (*bytes.Buffer, error)
- type Commit
- type Committer
- type Getter
- type Reverter
- type TrackingData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoChanges is returned when a diff operation finds no changes. ErrNoChanges = usererror.New("No changes") )
Functions ¶
func Alias ¶
Alias creates an alias when the passed in alias is empty. It works by removing leading dots and file extensions from the path. Examples:
~/.vimrc: vimrc ~/.config/i3/config: config ~/.config/alacritty/alacritty.yml: alacritty
func CheckAlias ¶
CheckAlias checks whether the alias is a valid format.
func Diff ¶
func Diff(g Getter, hash1, hash2 string) (*gotextdiff.Unified, error)
Runs a diff on the revision at hash1 against the revision at hash2. If hash2 is empty, compares the dirty content of the file. Returns an usererror when there is no difference.
func IsClean ¶
IsClean returns whether the dirty content matches the hash. Returns true when there is no dirty content.
func ShortenHash ¶
ShortenHash shortens a hash to a more friendly size.
func Uncompress ¶
Uncompress uncompresses bytes. Bytes are expected to be zlib compressed.
Types ¶
type Commit ¶
type Commit struct { Hash string `json:"hash"` Message string `json:"message"` Timestamp int64 `json:"timestamp"` // Unix timestamp. }
Commit represents a file revision.
type Committer ¶
type Committer interface { Getter HasCommit(hash string) (exists bool, err error) SaveCommit(buff *bytes.Buffer, c *Commit) error }
Committer is an interface for saving saving commits.
type Getter ¶
type Getter interface { DirtyContent() (contents []byte, err error) // Uncommitted changes. Revision(hash string) (revision []byte, err error) // Revision at hash. }
Getter is an interface that wraps methods for reading tracked files.
type Reverter ¶
type Reverter interface { Getter HasCommit(hash string) (exists bool, err error) Revert(buff *bytes.Buffer, hash string) (err error) }
Reverter is the interface that wraps methods needed for reverting a tracked file.
type TrackingData ¶
type TrackingData struct { Path string `json:"path"` Revision string `json:"revision"` Commits []Commit `json:"commits"` }
TrackingData is the data that dotfile uses to track files.
func MergeTrackingData ¶
func MergeTrackingData(old, new *TrackingData) (merged *TrackingData, newHashes []string, err error)
MergeTrackingData merges the new data into old. Returns the merged data and a slice of the hashes that are new.
func (*TrackingData) MapCommits ¶
func (td *TrackingData) MapCommits() map[string]*Commit
MapCommits maps hashes to commits.