Documentation
¶
Overview ¶
Package local tracks files by writing to JSON files in the dotfile directory.
For every new file that is tracked a new .json file is created. For each commit on a tracked file, a new file is created with the same name as the hash.
Example: ~/.emacs.d/init.el is added with alias "emacs". Supposing Storage.dir is ~/.config/dotfile, then the following files are created:
~/.config/dotfile/emacs.json ~/.config/dotfile/emacs/8f94c7720a648af9cf9dab33e7f297d28b8bf7cd
The emacs.json file would look something like this:
{ "path": "~/.emacs.d/init.el", "revision": "8f94c7720a648af9cf9dab33e7f297d28b8bf7cd" "commits": [{ "hash": "8f94c7720a648af9cf9dab33e7f297d28b8bf7cd", "timestamp": 1558896290, "message": "Initial commit" }] }
Index ¶
- Variables
- func DefaultConfigPath() (string, error)
- func DefaultStorageDir() (storageDir string, err error)
- func List(storageDir string, path bool) ([]string, error)
- func ListAliases(storageDir string) func() []string
- func SetConfig(path, key, value string) error
- type Config
- type Storage
- func (s *Storage) DirtyContent() ([]byte, error)
- func (s *Storage) Forget() error
- func (s *Storage) HasCommit(hash string) (exists bool, err error)
- func (s *Storage) JSON() ([]byte, error)
- func (s *Storage) Move(newPath string, parentDirs bool) error
- func (s *Storage) Path() (string, error)
- func (s *Storage) Pull(client *dotfileclient.Client) error
- func (s *Storage) Push(client *dotfileclient.Client) error
- func (s *Storage) Remove() error
- func (s *Storage) RemoveCommits() error
- func (s *Storage) Rename(newAlias string) error
- func (s *Storage) Revert(buff *bytes.Buffer, hash string) error
- func (s *Storage) Revision(hash string) ([]byte, error)
- func (s *Storage) SaveCommit(buff *bytes.Buffer, c *dotfile.Commit) error
- func (s *Storage) SetTrackingData() error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotTracked is returned when the current alias in storage is not tracked. ErrNotTracked = errors.New("file not tracked") // ErrNoData is returned when a method expects non nil file data. ErrNoData = errors.New("tracking data not loaded") )
Functions ¶
func DefaultConfigPath ¶ added in v1.0.0
DefaultConfigPath returns the default config file.
func DefaultStorageDir ¶ added in v1.0.0
DefaultStorageDir returns the default location for storing dotfile information. Creates the location when it does not exist.
func List ¶ added in v1.0.0
List returns a slice of aliases for all locally tracked files. When the file has uncommitted changes an asterisks is added to the end.
func ListAliases ¶ added in v1.0.3
ListAliases returns a funtion that lists all aliases in the storage directory.
Types ¶
type Config ¶ added in v1.0.0
type Config struct { Remote string `json:"remote"` Username string `json:"username"` Token string `json:"token"` }
Config contains local user settings for dotfile.
func ReadConfig ¶ added in v1.0.0
ReadConfig reads the user's config. Creates a default file when it doesn't yet exist.
type Storage ¶
type Storage struct { Alias string // The name of the file that is being tracked. Dir string // The path to the folder where data will be stored. FileData *dotfile.TrackingData // The current file that storage is tracking. }
Storage provides methods for manipulating tracked files on the file system.
func InitializeFile ¶ added in v1.0.0
InitializeFile sets up a new file to be tracked. When alias is empty its generated from path. Returns a Storage that is loaded with the new file.
func (*Storage) DirtyContent ¶ added in v1.0.0
DirtyContent reads the current content of the tracked file. Returns nil when the file no longer exists.
func (*Storage) Path ¶ added in v1.0.0
Path gets the full path to the file. Utilizes $HOME to convert paths with ~ to absolute.
func (*Storage) Pull ¶ added in v1.0.0
func (s *Storage) Pull(client *dotfileclient.Client) error
Pull retrieves a file's commits from a dotfile server. Updates the local file with the new content from remote. FileData does not need to be set; its possible to pull a file that does not yet exist.
func (*Storage) Push ¶ added in v1.0.0
func (s *Storage) Push(client *dotfileclient.Client) error
Push pushes a file's commits to a remote dotfile server. Updates the remote file with the new content from local.
func (*Storage) RemoveCommits ¶ added in v1.0.0
RemoveCommits removes all commits except for the current.
func (*Storage) SaveCommit ¶
SaveCommit saves a commit to the file system. Creates a new directory when its the first commit. Updates the file's revision field to point to the new hash.
func (*Storage) SetTrackingData ¶ added in v1.0.0
SetTrackingData reads the tracking data from the filesystem into FileData.