Documentation ¶
Overview ¶
Package git provides functions for running git and git-annex shell commands.
Index ¶
- Constants
- Variables
- func Add(filepaths []string, addchan chan<- RepoFileStatus)
- func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus)
- func AnnexCommand(args ...string) shell.Cmd
- func AnnexContentLocation(key string) (string, error)
- func AnnexDescribe(repository, description string) error
- func AnnexDrop(filepaths []string, dropchan chan<- RepoFileStatus)
- func AnnexFind(paths []string) (map[string]AnnexFindRes, error)
- func AnnexFromKey(key, filepath string) error
- func AnnexFsck(paths []string) error
- func AnnexGet(filepaths []string, getchan chan<- RepoFileStatus)
- func AnnexGetKey(key string, getchan chan<- RepoFileStatus)
- func AnnexInit(description string) error
- func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus)
- func AnnexPull(remote string) error
- func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus)
- func AnnexStatus(paths []string, statuschan chan<- AnnexStatusRes)
- func AnnexSync(content bool) error
- func AnnexUnlock(filepaths []string, unlockchan chan<- RepoFileStatus)
- func AnnexWhereis(paths []string, wichan chan<- AnnexWhereisRes)
- func BranchSetUpstream(name string) error
- func CatFileContents(revision, filepath string) ([]byte, error)
- func CatFileType(object string) (string, error)
- func Checkout(hash string, paths []string) error
- func Checkwd() error
- func Clone(remotepath string, repopath string, clonechan chan<- RepoFileStatus)
- func Command(args ...string) shell.Cmd
- func Commit(commitmsg string) error
- func CommitEmpty(commitmsg string) error
- func ConfigGet(key string) (string, error)
- func ConfigGetLocal(key string) (string, error)
- func ConfigSet(key, value string) error
- func ConfigUnset(key string) error
- func CopyFile(src, dest string) error
- func DescribeIndex() (string, error)
- func DescribeIndexShort(paths []string) (string, error)
- func DiffUpstream(paths []string, upstream string, diffchan chan<- string)
- func FindRepoRoot(path string) (string, error)
- func GetAnnexVersion() (string, error)
- func GetGitVersion() (string, error)
- func GetHostKey(gitconf config.GitCfg) (hostkeystr, fingerprint string, err error)
- func GetKnownHosts() (string, error)
- func Init(bare bool) error
- func IsDirect() bool
- func IsVersion6() bool
- func LogDiffStat(count uint, paths []string, showdeletes bool) (map[string]DiffStat, error)
- func LsFiles(args []string, lschan chan<- string)
- func LsRemote(remote string) (string, error)
- func PrivKeyPath() map[string]string
- func Pull(remote string) error
- func Push(remote string, pushchan chan<- RepoFileStatus)
- func RemoteAdd(name, url string) error
- func RemoteRemove(name string) error
- func RemoteShow() (map[string]string, error)
- func RevCount(a, b string) (int, error)
- func RevParse(rev string) (string, error)
- func SetBare(state bool)
- func SetGitUser(name, email string) error
- func WriteKnownHosts() error
- type AnnexFindRes
- type AnnexInfoRes
- type AnnexStatusRes
- type AnnexWhereisRes
- type DiffStat
- type Error
- type GinCommit
- type KeyFile
- type KeyPair
- type Object
- type RepoFileStatus
Constants ¶
const ( // Constant errors NotRepository = Error("Not a repository") NotAnnex = Error("No annex found") UpgradeRequired = Error("Repository upgrade needed") )
Variables ¶
var RawMode bool = false
RawMode disables --json output for annex commands
Functions ¶
func Add ¶
func Add(filepaths []string, addchan chan<- RepoFileStatus)
Add adds paths to git directly (not annex). In direct mode, files that are already in the annex are explicitly ignored. In indirect mode, adding annexed files to git has no effect. The status channel 'addchan' is closed when this function returns. (git add)
func AnnexAdd ¶
func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus)
AnnexAdd adds paths to the annex. Files specified for exclusion in the configuration are ignored automatically. The status channel 'addchan' is closed when this function returns. (git annex add)
func AnnexCommand ¶
AnnexCommand sets up a git annex command with the provided arguments and returns a GinCmd struct.
func AnnexContentLocation ¶
AnnexContentLocation returns the location of the content for a given annex key. This is the location of the content file in the object store. If the annexed content is not available locally, the function returns an error.
func AnnexDescribe ¶
AnnexDescribe changes the description of a repository. (git annex describe)
func AnnexDrop ¶
func AnnexDrop(filepaths []string, dropchan chan<- RepoFileStatus)
AnnexDrop drops the content of specified files. The status channel 'dropchan' is closed when this function returns. (git annex drop)
func AnnexFind ¶
func AnnexFind(paths []string) (map[string]AnnexFindRes, error)
AnnexFind lists available annexed files in the current directory. Specifying 'paths' limits the search to files matching a given path. Returned items are indexed by their annex key. (git annex find)
func AnnexFromKey ¶
AnnexFromKey creates an Annex placeholder file at a given location with a specific key. The creation is forced, so there is no guarantee that the key refers to valid repository content, nor that the content is still available in any of the remotes. The location where the file is to be created must be available (no directories are created). (git annex fromkey --force)
func AnnexFsck ¶
AnnexFsck runs fsck (filesystem check) on the specified files, fixing any issues with the annexed files in the working tree.
func AnnexGet ¶
func AnnexGet(filepaths []string, getchan chan<- RepoFileStatus)
AnnexGet retrieves the content of specified files. The status channel 'getchan' is closed when this function returns. (git annex get)
func AnnexGetKey ¶
func AnnexGetKey(key string, getchan chan<- RepoFileStatus)
AnnexGetKey retrieves the content of a single specified key. The status channel 'getchan' is closed when this function returns. (git annex get)
func AnnexLock ¶
func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus)
AnnexLock locks the specified files and directory contents if they are annexed. If an unlocked file has modifications, it wont be locked and an error will be returned for that file. The status channel 'lockchan' is closed when this function returns. (git annex lock)
func AnnexPull ¶
AnnexPull downloads all annexed files. Optionally also downloads all file content. (git annex sync --no-push [--content])
func AnnexPush ¶
func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus)
AnnexPush uploads all changes and new content to the default remote. The status channel 'pushchan' is closed when this function returns. (git annex sync --no-pull; git annex copy --to=<defaultremote>)
func AnnexStatus ¶
func AnnexStatus(paths []string, statuschan chan<- AnnexStatusRes)
AnnexStatus returns the status of a file or files in a directory The output channel 'statuschan' is closed when this function returns. (git annex status)
func AnnexSync ¶
AnnexSync performs a bidirectional synchronisation between local and remote repositories, automatically resolving merge conflicts. (git annex sync --resolvemerge)
func AnnexUnlock ¶
func AnnexUnlock(filepaths []string, unlockchan chan<- RepoFileStatus)
AnnexUnlock unlocks the specified files and directory contents if they are annexed The status channel 'unlockchan' is closed when this function returns. (git annex unlock)
func AnnexWhereis ¶
func AnnexWhereis(paths []string, wichan chan<- AnnexWhereisRes)
AnnexWhereis returns information about annexed files in the repository The output channel 'wichan' is closed when this function returns. (git annex whereis)
func BranchSetUpstream ¶
BranchSetUpstream sets the default upstream remote for the current branch. (git branch --set-upstream-to=)
func CatFileContents ¶
CatFileContents performs a git-cat-file of a specific file from a specific commit and returns the file contents (as bytes).
func CatFileType ¶
CatFileType returns the type of a given object at a given revision (blob, tree, or commit)
func Checkout ¶
Checkout performs a git checkout of a specific commit. Individual files or directories may be specified, otherwise the entire tree is checked out.
func Checkwd ¶
func Checkwd() error
Checkwd checks whether the current working directory is in a git repository. Returns NotRepository if the working directory is not inside a repository. Returns NotAnnex if the working directory is inside a repository but there is no annex. Returns UpgradeRequired if the annex is an old version (< v7).
func Clone ¶
func Clone(remotepath string, repopath string, clonechan chan<- RepoFileStatus)
Clone downloads a repository and sets the remote fetch and push urls. The status channel 'clonechan' is closed when this function returns. (git clone ...)
func Command ¶
Command sets up an external git command with the provided arguments and returns a GinCmd struct.
func Commit ¶
Commit records changes that have been added to the repository with a given message. (git commit)
func CommitEmpty ¶
CommitEmpty performs a commit even when there are no new changes added to the index. This is useful for initialising new repositories with a usable HEAD. In indirect mode (non-bare repositories) simply uses git commit with the '--allow-empty' flag. In direct mode it uses git-annex sync. (git commit --allow-empty or git annex sync --commit)
func ConfigGet ¶
ConfigGet returns the value of a given git configuration key using the default git configuration. The returned key is always a string. (git config --get)
func ConfigGetLocal ¶
ConfigGetLocal returns the value of a given git configuration key using the local git configuration only. The returned key is always a string. (git config --local --get)
func ConfigUnset ¶
ConfigUnset unsets a configuration value in the local git config. (git config unset --local)
func DescribeIndex ¶
DescribeIndex returns a string which describes the git (annex) index. It is constructed using the result of 'git annex status'. The resulting message can be used to inform the user of changes that are about to be uploaded and as a long commit message.
func DescribeIndexShort ¶
DescribeIndexShort returns a string which represents a condensed form of the git (annex) index. It is constructed using the result of 'git annex status'. The description is composed of the file count for each status: added, modified, deleted If 'paths' are specified, the status output is limited to files and directories matching those paths.
func DiffUpstream ¶
DiffUpstream returns, through the provided channel, the names of all files that differ from the default remote branch. The output channel 'diffchan' is closed when this function returns. (git diff --name-only --relative @{upstream})
func FindRepoRoot ¶
FindRepoRoot returns the absolute path to the root of the repository. For bare repositories, it returns an empty string, but no error. (git rev-parse --show-toplevel)
func GetAnnexVersion ¶
GetAnnexVersion returns the version string of the system's git-annex.
func GetGitVersion ¶
GetGitVersion returns the version string of the system's git binary.
func GetHostKey ¶
GetHostKey takes a git server configuration, queries the server via SSH, and returns the public key of the host (in the format required for the known_hosts file) and the key fingerprint.
func GetKnownHosts ¶
GetKnownHosts returns the path to the known_hosts file. If the file does not exist it is created by calling WriteKnownHosts.
func Init ¶
Init initialises the current directory as a git repository. The repository is optionally initialised as bare. (git init [--bare])
func IsDirect ¶
func IsDirect() bool
IsDirect returns true if the repository in a given path is working in git annex 'direct' mode. If path is not a repository, or is not an initialised annex repository, the result defaults to false. If the path is a repository and no error was raised, the result it cached so that subsequent checks are faster.
func IsVersion6 ¶
func IsVersion6() bool
IsVersion6 returns true if the repository in a given path is working in git annex 'direct' mode. If path is not a repository, or is not an initialised annex repository, the result defaults to false.
func LogDiffStat ¶
func LsFiles ¶
LsFiles lists all files known to git. The output channel 'lschan' is closed when this function returns. (git ls-files)
func LsRemote ¶
LsRemote performs a git ls-remote of a specific remote. The argument can be a name or a URL. (git ls-remote)
func PrivKeyPath ¶
PrivKeyPath returns a map with the full path for all the currently available private key files indexed by the server alias for each key.
func Push ¶
func Push(remote string, pushchan chan<- RepoFileStatus)
Push uploads all small (git) files to the server. (git push)
func RemoteRemove ¶
RemoteRemove removes the remote named name from the repository configuration.
func RemoteShow ¶
RemoteShow returns the configured remotes and their URL. (git remote -v show -n)
func RevParse ¶
RevParse parses an argument and returns the unambiguous, SHA1 representation. (git rev-parse)
func SetGitUser ¶
SetGitUser sets the user.name and user.email configuration values for the local git repository.
func WriteKnownHosts ¶
func WriteKnownHosts() error
WriteKnownHosts creates a known_hosts file in the config directory with all configured host keys.
Types ¶
type AnnexFindRes ¶
type AnnexFindRes struct { Hashdirlower string Hashdirmixed string Key string Humansize string Backend string File string Keyname string Bytesize string Mtime string }
AnnexFindRes holds the result of a git annex find invocation for one file.
type AnnexInfoRes ¶
type AnnexInfoRes struct { TransfersInProgress []interface{} `json:"transfers in progress"` LocalAnnexKeys int `json:"local annex keys"` AvailableLocalDiskSpace string `json:"available local disk space"` AnnexedFilesInWorkingTree int `json:"annexed files in working tree"` File interface{} `json:"file"` TrustedRepositories []interface{} `json:"trusted repositories"` SizeOfAnnexedFilesInWorkingTree string `json:"size of annexed files in working tree"` LocalAnnexSize string `json:"local annex size"` Command string `json:"command"` UntrustedRepositories []interface{} `json:"untrusted repositories"` SemitrustedRepositories []struct { Description string `json:"description"` Here bool `json:"here"` UUID string `json:"uuid"` } `json:"semitrusted repositories"` Success bool `json:"success"` BloomFilterSize string `json:"bloom filter size"` BackendUsage struct { SHA256E int `json:"SHA256E"` WORM int `json:"WORM"` } `json:"backend usage"` RepositoryMode string `json:"repository mode"` }
AnnexInfoRes holds the information returned by AnnexInfo
func AnnexInfo ¶
func AnnexInfo() (AnnexInfoRes, error)
AnnexInfo returns the annex information for a given repository (git annex info)
type AnnexStatusRes ¶
type AnnexStatusRes struct { Status string `json:"status"` File string `json:"file"` Err error `json:"err"` }
AnnexStatusRes for getting the (annex) status of individual files
type AnnexWhereisRes ¶
type AnnexWhereisRes struct { File string `json:"file"` Command string `json:"command"` Note string `json:"note"` Success bool `json:"success"` Untrusted []string `json:"untrusted"` Key string `json:"key"` Whereis []struct { Here bool `json:"here"` UUID string `json:"uuid"` URLs []string `json:"urls"` Description string `json:"description"` } Err error `json:"err"` }
AnnexWhereisRes holds the output of a "git annex whereis" command
type GinCommit ¶
type GinCommit struct { Hash string `json:"hash"` AbbreviatedHash string `json:"abbrevhash"` AuthorName string `json:"authorname"` AuthorEmail string `json:"authoremail"` Date time.Time `json:"date"` Subject string `json:"subject"` Body string `json:"body"` FileStats DiffStat }
GinCommit describes a commit, retrieved from the git log.
type KeyFile ¶
KeyFile holds the absolute path and filename of the current logged in user's key file.
type KeyPair ¶
KeyPair simply holds a private-public key pair as strings, with no extra information.
func MakeKeyPair ¶
MakeKeyPair generates and returns a private-public key pair.
type Object ¶
Object contains the information for a tree or blob object in git
type RepoFileStatus ¶
type RepoFileStatus struct { // The name of the file. FileName string `json:"filename"` // The state of the operation. State string `json:"state"` // Progress of the operation, if available. If partial progress isn't available or applicable, this will be empty. Progress string `json:"progress"` // The data rate, if available. Rate string `json:"rate"` // original cmd input RawInput string `json:"rawinput"` // original command output RawOutput string `json:"rawoutput"` // Errors Err error }
RepoFileStatus describes the status of files when being added to the repo or transferred to/from remotes.
func (RepoFileStatus) MarshalJSON ¶
func (s RepoFileStatus) MarshalJSON() ([]byte, error)
MarshalJSON overrides the default marshalling of RepoFileStatus to return the error string for the Err field.