git
Description
A Git interface based on the libgit2 library.
The current version of this extension requires at least libgit2 version 0.23.0, and it has not been tested on versions newer than 0.26.0.
The source for this egg is available here.
Usage
The library is split into two modules, git and libgit2:
(import (git)) ; or... (import (git libgit2))
- The (git libgit2) library is just the libgit2 API, thinly wrapped. Most of the function signatures remain the same, with a few exceptions:
- Opaque structures are represented as pointer objects (e.g. git_commit).
- Public structures are represented as locatives (e.g. git_oid).
- Memory for out parameters and other structures that would typically go on the stack is allocated automatically.
- Return values are checked where appropriate, signaling an exception of type git when nonzero.
- The (git) library is a higher-level interface, providing Scheme record types for each libgit2 structure and a more Scheme-friendly API.
It's not recommended to mix the two without prefixing one or the other's imports, as the two libraries share many identifiers.
The following documentation applies to the (git) module.
API
Repository
[record] repository[procedure] (repository? obj) => boolean
A repository corresponds to an on-disk Git repository.
[procedure] (create-repository [path [bare]]) => repositoryCreates and returns a new repository at the given path, or the value of current-directory if no path is given. If bare is given and not #f, the repository will be created without a working directory. An error is signaled if the path is invalid or the repository cannot be created.
[procedure] (repository-open [path]) => repositoryOpens the Git repository indicated by path, or the value of current-directory if no path is given. path may point to a bare repository, a working directory containing a ".git" directory, or a ".git" directory directly.
[procedure] (repository-path repository) => stringReturns the absolute path to the given repository's Git directory, either the topmost directory in the project (if the repository is bare) or the ".git" subdirectory.
[procedure] (repository-working-directory repository) => (or string false)Returns the absolute path to the given repository's working directory, or #f if the repository is bare.
[procedure] (repository-ref repository ref) => (or object false)Looks up a Git object in the given repository. ref may be a SHA1 string, oid, reference, blob, commit, tag or tree. The returned object will be of type blob, commit, tag or tree, or #f if no object matching the given ref is found.
[procedure] (repository-empty? repository) => boolean[procedure] (repository-bare? repositoy) => boolean
Returns a boolean indicating whether the given repository is empty (contains no commits) or bare (an exposed git directory without a working directory).
[procedure] (repository-head-orphan? repositoy) => boolean[procedure] (repository-head-detached? repositoy) => boolean
[procedure] (repository-head-unborn? repositoy) => boolean
Returns a boolean indicating whether the given repository's HEAD (a symbolic reference) is orphaned (unreferenced under the refs namespace), detached (refering to a commit rather than a branch), or has yet to be created, respectively.
OID
[record] oid[procedure] (oid? obj) => boolean
An oid is a unique reference to a Git object, corresponding to a 40-character SHA1 object name.
[procedure] (string->oid string) => oidCreates an oid from the given string, which should be a 40-character SHA1 hash. An error is signaled if the string is not a valid hash.
[procedure] (oid->string oid [length]) => stringReturns the string representation of the given oid. The optional integer length specifies the length of the returned string, up to 40 characters.
[procedure] (oid->path oid) => stringReturns the string representation of the given oid in the form "xx/...", where "xx" is the first two characters of the SHA1 and "..." is the remainder.
[procedure] (oid=? oid1 oid2) => booleanIndicates whether the two oids are the equivalent.
Revspec
[procedure] (parse-revision-specification string) => (values object object)Attempts to parse a string as a Git revision specification, returning two values:
- If string specifies a range of revisions, the start and end commit objects.
- If string specifies a single revision, the commit object and #f.
- If string is invalid or fails to match a revision, #f for both values.
For more information about specifying revisions, see http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions.
Reference
[record] reference[procedure] (reference? obj) => boolean
A reference is a direct or indirect pointer to a Git commit object. A repository's HEAD is a common example: it is a symbolic reference, referring to the immediate reference "refs/heads/master", which in turn points at a commit.
[procedure] (reference repository ref) => referenceReturns the reference specified by the given string ref from the repository. ref must be a string referring to a valid reference, such as HEAD, "ref/heads/master", or "refs/tags/v0.1.0". An error is signalled if the reference doesn't exists.
[procedure] (reference-name reference) => stringReturns the name of the given reference.
[procedure] (reference-type reference) => symbolReturns the type symbol of the given reference, which will be either oid or symbolic.
[procedure] (reference-remote? reference) => boolean[procedure] (reference-branch? reference) => boolean
[procedure] (reference-tag? reference) => boolean
These procedures return boolean values indicating whether the given reference is a remote, branch, or tag-type reference, respectively.
[procedure] (references-fold kons knil repository [glob]) => objectFolds over the given repository's references in unspecified order.
An optional glob pattern string may be used to filter the references returned. If given, it will be matched in "glob" style where a #\? matches any letter, a #\* matches any sequence of letters, and square brackets match a range of characters (such as "[0-9]" for digits). If no glob is given, all references will be provided to kons.
[procedure] (references repository [type]) => (list-of reference)Returns a list of all references in the given repository. A type symbol may be given to filter the references, as in references-fold. The order of the resulting list is unspecified.
[procedure] (repository-head repository) => (or reference false)Returns a reference to this repository's HEAD (resolved to an OID), of #f if it doesn't exist.
[procedure] (reference-resolve reference) => referenceRecursively dereferences the given (possibly symbolic) reference, returning a new non-symbolic reference pointing refering directly to an oid.
[procedure] (reference-target reference) => oidReturns the oid of the object which the given reference refers. Symbolic references are peeled until a non-symbolic reference is found, as with reference-resolve.
[procedure] (reference-name-set! reference name [force]) => void[procedure] (reference-target-set! reference target) => void
reference-name-set! changes the name of the given reference to the string name. If force is given and nonfalse, any previously-existing reference of the given name will be overwritten.
reference-target-set! updates a reference to refer to the given target. If reference is an immediate reference (referring to an object ID), target must be an oid, commit, or SHA1 string. If reference is symbolic, target must be a reference or reference name. It is an error to assign a symbolic reference an OID target and vice-versa.
On success, the on-disk repository is updated immediately.
[procedure] (create-reference repository #!key name target [symbolic] [force]) => referenceCreates and returns a new reference in the given repository for the specified name and target. If symbolic is given and not #f, the created reference will be so, and target must be a reference name or reference. Otherwise, target must be a SHA1 string, oid, commit or reference to a commit. If a reference of the given name exists and force is not given or #f, an error is signalled. Otherwise, creation is forced and the old reference will be overwritten.
On success, the on-disk repository is updated immediately.
[procedure] (reference-delete reference) => voidDeletes the given reference from its repository.
On success, the on-disk repository is updated immediately.
Branch
[procedure] (create-branch repository name target [force]) => referenceCreates a new branch in the given repository of the given name and target and returns a reference to the new branch. target must be a commit or tag belonging to the repository. If a branch of the given name exists and force is not given or #f, an error is signalled. Otherwise, creation is forced and the old branch is be overwritten.
On success, the on-disk repository is updated immediately.
[procedure] (branch repository name [type]) => (or reference false)Retrieves a reference to the branch of the given name from the repository. name should be a string naming a branch without a leading reference namespace such as "refs/heads/" or "refs/remotes". An error is signaled if no such branch exists.
A type symbol may be given, either local or remote, to specify what type of branch should be looked up; by default, local is used.
[procedure] (branches-fold kons knil repository [type]) => objectFolds over the given repository's branches.
A type symbol may be given, either local, remote, or all, to specify what type of branches should be listed; by default, all is used.
[procedure] (branches repository [type]) => (list-of reference)Returns a list reference objects for each branch in the given repository. A type symbol may be given to filter the branches, as in branches-fold. The order of the resulting list is unspecified.
[procedure] (branch-head? reference) => booleanDetermines whether the given branch reference is its repository's current HEAD.
[procedure] (branch-name reference) => stringReturns the name of the given branch reference. This is similar to reference-name, but the leading reference namespace (e.g. "refs/heads") is omitted.
[procedure] (branch-name-set! reference name [force]) => voidRenames the given branch reference to name, which should be a string. If force is given and not false, any existing branch with the given name will be overwritten.
On success, the on-disk repository is updated immediately.
[procedure] (branch-delete reference) => voidDeletes the given branch reference from its repository.
On success, the on-disk repository is updated immediately.
Generic Procedures
These procedures can be used on any objects of the four main Git object types: commit, tree, tag and blob.
[procedure] (object-id object) => oidReturns the oid of the given object, which must be a commit, tree, tag or blob.
[procedure] (object-sha object [length]) => stringReturns the SHA1 identifier corresponding to the given object, which may be a commit, tree, tag blob, reference, oid or string.
[procedure] (object-type object) => (or symbol false)Returns a symbol specifying the type of the given object, which must be a commit, tree, tag or blob. #f is returned if the object's type cannot be determined.
[procedure] (object=? object1 object2) => booleanIndicates whether the two Git objects represent the same thing (judging by their respective oids). Each object should be of type commit, tree, tag or blob.
Blob
[record] blob[procedure] (blob? obj) => boolean
A blob corresponds to Git's Blob object type. It represents a chunk of data, generally a file.
Beware name collisions with CHICKEN's built-in blob data type.
[procedure] (blob repository ref) => blobReturns the blob specified by the given ref from the repository. ref may be a SHA1 string, oid, or blob. An error is signaled if no such blob exists.
[procedure] (blob-id commit) => oidReturns the oid of the given blob.
[procedure] (blob-content blob) => blobReturns a blob (of the CHICKEN built-in type) of the contents of the given blob (of the Git object type).
[procedure] (blob-length blob) => intReturns the size in bytes of the given blob.
[procedure] (blob-binary? blob) => booleanIndicates whether the given blob is (likely to be) a binary chunk or not.
[procedure] (create-blob repository source) => blobCreates a new blob in the given repository.
source is the data source for the blob, and may be a blob (of the CHICKEN built-in type) or a pathname string indicating a file on the local disk or, if such a file isn't present, a file relative to the repository's working directory.
On success, the on-disk repository is updated immediately.
Commit
[record] commit[procedure] (commit? obj) => boolean
A commit corresponds to Git's commit object type.
[procedure] (commit repository ref) => commitReturns the commit specified by the given ref from the repository. ref may be a SHA1 string, oid, reference or commit. An error is signaled if no such commit exists.
[procedure] (commits-fold kons knil repository #!key [initial] [hide] [sort]) => objectFolds over the given repository's commits. If an initial commit or SHA1 is given, only commits that are ancestors of that revision will be returned. If a list of revisions to hide is given, they and their ancestors will be ignored. If a sort order is specified, commits will be collected in the given order; this sort order must be one of the symbols none, topo, time or reverse, or a list of such symbols.
[procedure] (commits repository #!rest args) => (list-of commit)Returns a list of the commits in the given repository. args follows the #!key arguments specification for commits-fold. The order of the resulting list is opposite that of a call to commits-fold with the same arguments.
[procedure] (commit-id commit) => oidReturns the oid for the given commit.
[procedure] (commit-time commit) => int[procedure] (commit-time-offset commit) => int
commit-time and commit-time-offset return the timestamp of the given commit and its UTC offset in minutes, respectively.
[procedure] (commit-message commit) => string[procedure] (commit-message-encoding commit) => string
Returns the full commit message or message encoding for the given commit.
[procedure] (commit-header commit) => stringReturns a string header for the given commit, which is a textual display of its author, committer, tree and parent commit.
[procedure] (commit-tree commit) => tree[procedure] (commit-tree-id commit) => oid
Return the tree associated with the given commit and its oid, respectively.
[procedure] (commit-author commit) => signature[procedure] (commit-committer commit) => signature
commit-author and commit-committer return the given commit's respective signatures.
[procedure] (commit-parentcount commit) => int[procedure] (commit-parent commit [n]) => (or commit false)
[procedure] (commit-parent-id commit [n]) => (or oid false)
[procedure] (commit-parents commit) => (list-of commit)
[procedure] (commit-ancestor commit [n]) => (or commit false)
commit-parentcount returns the number of parents of the given commit.
commit-parent returns the nth parent of the given commit, or the first parent if no n is given. If the commit has no parent, #f is returned.
commit-parent-id is as commit-parent, but it returns the oid of the given commit's parent without first reading the parent commit from the repository.
commit-parents returns the possibly-empty list of all parents of the given commit. The order of this list is unspecified.
commit-ancestor returns the nth ancestor of the given commit, or #f is no such ancestor exists. n defaults to 1, meaning the commit's first parent (making (commit-ancestor c 1) equivalent to (commit-parent c)).
[procedure] (create-commit repository #!key message author [committer] [tree] [parents] [reference]) => commitCreates and returns a new commit in the given repository. The string message will be used as the commit's message and tree will be the file tree of the commit. If no tree is given, the current state of the repository's index is used. parents may be be a (possibly empty) list of commits to be used as this commit's ancestors. author and committer should be signatures; if committer is not given, author will be used for both. reference, if given and not #f, should be the reference or name of a reference that will be updated to point to the newly-created commit.
Note that if no reference is given, the commit will be created in Git's database but will not be reflected in any of the repository's branches. To update the the working branch with the new commit, for example, use "HEAD".
On success, the on-disk repository is updated immediately.
[procedure] (merge-base repository commit1 commit2) => commitReturns the nearest common ancestor for the given commits. commit1 and commit2 may be commits, commit oids, or SHA1 hashes.
Tag
[record] tag[procedure] (tag? obj) => boolean
A tag corresponds to Git's Tag object type, which is a way to mark a specific object as special in some way.
[procedure] (tag repository ref) => tagCreates and returns the tag specified by the given ref from the repository. ref may be a SHA1 string, oid, or tag. An error is signaled if no such tag exists.
[procedure] (tags-fold kons knil repository) => objectFolds over the given repository's tags in unspecified order.
[procedure] (tags repository) => (list-of tag)Returns a list of all tags in the given repository. The order of the resulting list is unspecified.
[procedure] (tag-id tag) => oidReturns the oid for the given tag.
[procedure] (tag-type tag) => symbolReturns the object type symbol of the target of the given tag, which will be one of commit, tree, blob, or tag.
[procedure] (tag-name tag) => string[procedure] (tag-message tag) => string
Return the name or message of the given tag.
[procedure] (tag-tagger tag) => signatureReturns the signature of the tag's creator.
[procedure] (tag-peel tag) => objectRecursively dereferences the given tag until a non-tag object to which it refers is found (and returned).
[procedure] (tag-target tag) => object[procedure] (tag-peel tag) => object
tag-target returns the object referred to by tag, which will be of type commit, tree, blob or tag.
Returns the object immediately referred to by tag, which will be of type commit, tree, blob or tag.
[procedure] (tag-delete tag) => voidDestroys the given tag.
On success, the on-disk repository is updated immediately.
[procedure] (create-tag repository #!key target name message tagger [force]) => tagCreates and returns a new tag in the given repository for the specified name, message and target. name and message must be strings, tagger must be a signature,and target must be a commit, tree or blob. If a tag of the given name exists and force is not given or #f, an error is signalled. Otherwise, creation is forced and the old tag will be overwritten.
On success, the on-disk repository is updated immediately.
Tree
[record] tree[procedure] (tree? obj) => boolean
A tree corresponds to Git's Tree object type, which represents a directory tree.
[procedure] (tree repository ref) => treeReturns the tree specified by the given ref from the repository. ref may be a SHA1 string, oid, or tree. An error is signaled if no such tree exists.
[procedure] (tree-id tree) => oidReturns the oid for the given tree.
[procedure] (tree-entrycount tree) => intReturns the number of entries in the given tree. This count does not include entries of contained directories.
[procedure] (tree-ref tree key) => (or tree-entry false)Returns a tree-entry object for the given key from the tree, or #f if no such tree entry is found. key may be a zero-based integer index or a pathname string relative to the repository's working directory.
[procedure] (tree-fold kons knil tree) => objectFolds over each path and accompanying tree-entry in the given tree in unspecified order.
Note that kons should be a function of three arguments; the path to the current tree-entry (a string, relative to the repository's working directory), the current tree-entry, and the current state of the fold.
[procedure] (tree-entries tree) => (list-of (pair string tree-entry))Returns an alist of all tree-entry objects in the given tree, whose keys are pathname strings indicating each tree-entry's location in the tree and whose values are the tree-entry objects themselves. The order of the resulting list is unspecified.
[procedure] (create-tree repository [index]) => treeCreates and returns a new tree object from the state of the given index in the given repository.
If index is not given, a fresh index for the repository is used. This means the resulting tree will be identical to that of the repository's HEAD.
On success, the new value is written immediately to disk.
Tree Entry
[record] tree-entry[procedure] (tree-entry? obj) => boolean
A tree-entry represents a single node in a tree object.
[procedure] (tree-entry-id tree-entry) => oidReturns the oid of the given tree-entry.
[procedure] (tree-entry-name tree-entry) => stringReturns the name of the given tree-entry.
[procedure] (tree-entry-attributes tree-entry) => intReturns the Unix file attributes of the given tree-entry.
[procedure] (tree-entry-type tree-entry) => symbolReturns the object type symbol, either tree or blob, of the given tree-entry.
[procedure] (tree-entry->object [repository] tree-entry) => objectReturns an object of type tree or blob from the given tree-entry and repository, which must be the owner of the tree-entry.
If no repository is given, tree-entry->object will attempt to determine the owning repository from the tree-entry. This is only possible if the tree-entry belongs to a tree; if it belongs to a tree-builder, instead, an error will be signaled.
Tree Builder
[record] tree-builder[procedure] (tree-builder? obj) => boolean
A tree builder provides a way to construct tree objects in memory and write them to a repository, without using an index as an intermediary.
[procedure] (make-tree-builder object) => tree-builderCreates a new tree-builder. If object is a tree, it is used as the constructed tree's initial state. Otherwise, object must be a repository, and the resulting tree-builder is initialized with an empty tree.
[procedure] (tree-builder-insert tree-builder object name attributes) => tree-entryInserts object into the tree-builder's tree under the given filename name. The inserted object must be a tree or blob, and will have the given attributes (an integer file mode).
[procedure] (tree-builder-ref tree-builder path) => (or tree-entry false)Returns the tree-entry from the given tree-builder at path, which should be a filename string. If the requested file doesn't exist, #f is returned.
[procedure] (tree-builder-remove tree-builder path) => voidRemoves the object at the given path from the tree-builder's tree.
[procedure] (tree-builder-write tree-builder) => treeWrites the tree-builder's current state, modifying the on-disk repository on success. The resulting tree is returned.
[procedure] (tree-builder-clear tree-builder) => voidRemoves all objects from the given tree-builder.
Diff
[record] diff[procedure] (diff? obj) => boolean
A diff is the cumulative difference between two Git trees (or tree-like objects). It consists of a number of diff-deltas, each of which represents the difference in a single file.
[procedure] (diff repository [object1 [object2]]) => diffReturns a diff between two objects in the repository.
diff's behavior is as follows, given the following arguments:
- (): diff the repository's index to its working directory
- (index): diff the given index to the repository's working directory
- (tree): diff the given tree to the repository's working directory
- (tree tree): diff the given trees
- (tree index): diff the given tree to the given index
Folds over the given diff's diff-deltas in unspecified order.
[procedure] (diff-deltas {{diff}}) => (list-of diff-delta)Returns the list of diff-deltas for all changed files in the given diff.
[record] diff-delta[procedure] (diff-delta-path diff-delta) => string
[procedure] (diff-delta-old-file diff-delta) => diff-file
[procedure] (diff-delta-new-file diff-delta) => diff-file
[record] diff-file
[procedure] (diff-file? obj) => boolean
[procedure] (diff-file-id diff-file) => oid
[procedure] (diff-file-path diff-file) => string
[procedure] (diff-file-size diff-file) => integer
[procedure] (diff-file-mode diff-file) => integer
A diff-delta is the difference in a single file between two Git trees. Each delta has a path, a status, a pair of diff-files for the old and new files (retrieved by diff-delta-old-file and diff-delta-new-file, respectively), and a list of diff-hunks representing individual changes.
Each diff-file has an id, path, size and mode (Unix file attributes).
[procedure] (diff-delta-status diff-delta) => symbolReturns a symbol representing the status of a diff-delta, which will be one of the following symbols, or a list of them if the diff-delta's file is in multiple statuses:
unmodified added deleted modified renamed copied ignored untracked[procedure] (diff-patch diff n) => patch
Returns a patch for the nth diff-delta in the given diff.
[procedure] (diff-patches diff) => patchReturns a list of patches for all diff-deltas in the given diff.
[procedure] (diff->string diff) => stringReturns a string representation of the given diff as a patch.
This is equivalent to concatenating the string representations of each patch given by diff-patches.
[procedure] (diff-old-file diff) => (or diff-file false)[procedure] (diff-new-file diff) => (or diff-file false)
Returns the diff-file object for the old and new file of the given diff, respectively. If the file is added or deleted, #f will be returned for the diff's old or new file, respectively.
[procedure] (diff-delta-hunks diff-delta) => (list-of diff-hunk)Returns the list of diff-hunks in the given diff-delta.
[record] diff-hunk[procedure] (diff-hunk? obj) => boolean
[procedure] (diff-hunk-header diff) => string
[procedure] (diff-hunk-old-lines diff) => integer
[procedure] (diff-hunk-old-start diff) => integer
[procedure] (diff-hunk-new-lines diff) => integer
[procedure] (diff-hunk-new-start diff) => integer
A diff-hunk represents a group of changes in a diff, with some surrounding context. Each has a header describing the change, line counts and start offsets for the old and new versions of the hunk, and a list of diff-lines representing each added or deleted range of bytes in the group of changes.
[procedure] (diff-hunk-lines diff) => (list-of diff-line)[record] diff-line
[procedure] (diff-line? obj) => boolean
[procedure] (diff-line-origin diff) => char
[procedure] (diff-line-content diff) => string
[procedure] (diff-line-num-lines diff) => integer
[procedure] (diff-line-old-lineno diff) => integer
[procedure] (diff-line-new-lineno diff) => integer
A diff-line is a range of bytes in a diff-hunk and represents either an addition, a deletion, or a range that is present in both the old and new versions of the hunk but is included for context. Which of these a given diff-line corresponds to is indicated by its diff-line-origin, one of #\+, #\- or #\space.
Patch
[record] patch[procedure] (patch? obj) => boolean
A patch is a textual representation of a diff-delta.
[procedure] (patch->string patch) => stringReturns the string representation of the given patch.
[procedure] (patch-size patch) => integerReturns the total number of bytes in the patch, including hunk and line headers and context lines.
[procedure] (patch-stats patch) => (vector-of integer integer integer)Returns a three-element vector containing the number of lines of context, number of lines added, and number of lines deleted in the patch.
Status
[procedure] (file-status repository path) => symbolReturns the status of the file specified by path in the given repository.
This status will be one of the following symbols, or a list of them if the file is in multiple statuses:
current index/new index/modified index/deleted worktree/new worktree/modified worktree/deleted ignored[procedure] (file-statuses-fold kons knil repository) => object
Folds over each path and the corresponding file's status in the given repository's working directory in unspecified order.
Note that kons should be a function of three arguments; the pathname of the current file (a string, relative to the repository's working directory), the current status symbol, and the current state of the fold.
[procedure] (file-statuses repository) => (list-of (pair string symbol))Returns an alist of all file statuses in the given repository, whose keys are pathnames to each file and whose values are the status symbols of those files. The order of the resulting list is unspecified.
[procedure] (file-ignored? repository path) => booleanReturns a boolean indicating whether the given path in repository is ignored by Git or not.
Ignore
[procedure] (path-ignored? repository path) => booleanReturns a boolean indicating whether the given path in repository is ignored by Git or not. This is equivalent to file-ignored?.
[procedure] (ignore-add! repository glob) => voidAdds glob as an ignore rule to the given repository. Files matching this pattern will be ignored for all operations on the in-memory repository. Rules added in this way are not be persisted to the file system.
[procedure] (ignore-clear! repository) => voidRemoves all ignore rules that have been added to the repository by ignore-add!.
Note
[record] note[procedure] (note? obj) => boolean
A note is a type of reference, stored under the refs/notes namespace. It's used to associate some data (accessible via note-message) with an object.
[procedure] (note-message note) => string[procedure] (note-id note) => oid
note-message and note-id return the string content and oid of the given note, respectively.
[procedure] (note repository object [reference]) => noteReturns the note associated with the given object in the repository. reference may be a string specifying an alternative notes reference namespace, which defaults to "refs/notes/commits". An error is signaled if no such note exists.
[procedure] (delete-note repository #!key target author [committer] [reference]) => voidDeletes all notes for the given object target by the given author in the repository. author and committer should be a signatures, while reference may specify an alternative notes reference namespace, which defaults to "refs/notes/commits".
On success, the note is removed from disk immediately. An error is signaled if no such note exists.
[procedure] (create-note repository #!key message target reference author [committer] [force]) => noteCreates and returns a new note in the given repository with the specified message and target object. author and committer should be signatures, while reference may specify an alternative notes reference namespace, which defaults to "refs/notes/commits". If force is given and not #f, an existing note for the same target and author/committer will be overwritten; otherwise, an error will be signaled if such a note already exists.
On success, the on-disk repository is updated immediately.
[procedure] (notes-fold kons knil repository [reference]) => objectFolds over the given repository's notes in unspecified order.
reference may specify an alternative notes reference namespace, which defaults to "refs/notes/commits".
[procedure] (notes repository [reference]) => (list-of note)Returns a list of all notes in the given repository. The order of the resulting list is unspecified.
reference may specify an alternative notes reference namespace, which defaults to "refs/notes/commits".
Index
[record] index[procedure] (index? obj) => boolean
An index represents the on-disk state of Git's working tree. Changes made to a given index exist only in memory until written to disk using index-write.
[procedure] (index-open repository-or-path) => indexIt repository-or-path is a repository, index-open returns the repository's index. If it's a string, index-open creates and returns the index at the given path, signaling an error if such an index doesn't exist. It is not possible to open the index of a bare repository, and doing so will result in an exception.
[procedure] (index-entrycount index) => intReturns the total number of index entries entries of the given index, respectively. This is essentially a count of all files tracked by Git in a given repository.
[procedure] (index-read index) => voidUpdates the given index to reflect the current state of the on-disk repository.
[procedure] (index-write index) => voidWrites the state of the given index from memory onto disk, modifying the repository on success.
[procedure] (index-clear index) => voidRemoves all enries from a given index.
[procedure] (index-add index path [stage]) => voidAdds a given path, which must refer to a file relative to the index's repository, to the index. If an integer stage is given, it will be used as the staging number for the changes.
[procedure] (index-remove index ref) => voidRemoves an entry from the given index. ref may be a file path string or an zero-based integer index. If no entry is removed, #f is returned.
[procedure] (index-find index path) => intReturns the zero-based integer index of the file specified by path in the given index, signaling an error if it doesn't exist.
[procedure] (index-ref index key [type]) => (or index-entry false)Returns the index-entry from the index for the given key, which may be an zero-based integer index or a pathname string, or #f if no such entry exists. If a type symbol is given, either merged (the default behavior) or unmerged, the search will be limited to such entries.
Index Entry
[record] index-entry[procedure] (index-entry? obj) => boolean
An index-entry represents a tracked file in Git's working directory, belonging to an index.
[procedure] (index-entry-id index-entry) => oidReturns the oid referring to the given index-entry.
[procedure] (index-entry-path index-entry) => stringReturns the file path of the given index-entry relative to the owning repository's working directory.
[procedure] (index-entry-ctime index-entry) => int[procedure] (index-entry-mtime index-entry) => int
[procedure] (index-entry-dev index-entry) => int
[procedure] (index-entry-ino index-entry) => int
[procedure] (index-entry-size index-entry) => int
[procedure] (index-entry-stage index-entry) => int
[procedure] (index-entry-uid index-entry) => int
[procedure] (index-entry-gid index-entry) => int
[procedure] (index-entry-mode index-entry) => int
[procedure] (index-entry-flags index-entry) => int
[procedure] (index-entry-extended index-entry) => int
These methods return the file attributes for the given index-entry as it exists in its in-memory index.
ODB
[record] odb[procedure] (odb? obj) => boolean
An odb offers a direct interface to Git's internal object database.
[procedure] (odb-open repository-or-path) => odbIt repository-or-path is a repository, returns the repository's object database. If it is a string, creates and returns the object database at the given path, signaling an error if no such database exists.
[procedure] (odb-has-object? odb ref) => booleanDetermines if the given odb contains the given object ref, which should be a SHA1 string, oid or Git object of type commit, blob, tree or tag.
[procedure] (odb-read odb ref) => odb-objectReads the given object ref from the database, signaling an error if it doesn't exist. ref should be a SHA1 string, oid or Git object of type commit, blob, tree or tag.
[procedure] (odb-write odb data [type]) => oidWrites a given data blob to the odb, returning an oid referring to the newly-created object. The type of the stored data can be specified by an optional type symbol, which defaults to blob.
[procedure] (odb-hash odb data [type]) => oidReturns an oid reference for the given data blob as though it had been stored to the given odb but without writing it to disk. The type of the hashed data can be specified by an optional type symbol, which defaults to blob.
ODB Object
[record] odb-object[procedure] (odb-object? obj) => boolean
An odb-object is a reference to a blob of data in a Git object database.
[procedure] (odb-object-id odb-object) => oidReturns the oid for the given odb-object.
[procedure] (odb-object-size odb-object) => intReturns the size of the odb-object's data in bytes.
[procedure] (odb-object-type odb-object) => symbolReturns the object type symbol of the given odb-object.
[procedure] (odb-object-data odb-object) => blobReturns a blob consisting of the odb-object's data.
Signature
[record] signature[procedure] (signature? obj) => boolean
A signature is a record of the name, email, time and UTC offset of a given Git object.
[procedure] (make-signature name email [time [offset]]) => signatureReturns a new signature for the given name and email strings. If a timestamp time and integer offset are given, they will be used as the signature time; otherwise, the current time will be used.
Unlike the create-* functions, no representation of this signature is created in the repository; it exists only in memory until associated with a commit or tag.
[procedure] (signature-name signature) => string[procedure] (signature-email signature) => string
signature-name and signature-email return strings for the given signature's respective fields.
[procedure] (signature-time signature) => int[procedure] (signature-time-offset signature) => int
signature-time and signature-time-offset return the timestamp of the given signature and its UTC offset in minutes, respectively.
Checkout
[procedure] (checkout repository [object]) => voidcheckout updates files in the working directory and index of the given repository to match the state of object.
If object is an index, the repository's working directory will be updated to match the its state.
If object is a commit, tag or tree, the repository's working directory and index will both be updated to reflect its state.
If object is omitted or #f, the repository's working directory and index will both be updated to match the state of the repository's HEAD.
Note that checkout will silently delete untracked files and overwrite changes to tracked files in the repository's working directory.
Clone
[procedure] (clone url path) => voidClones the remote Git repository specified by url into the local pathname path.
On success, the branch indicated by the HEAD reference of the remote repository is checked out as a normal (i.e. non-bare) Git working directory.
An error is signaled if the clone fails for any reason.
Remote
[record] remote[procedure] (remote? obj) => boolean
A remote represents a remote repository.
[procedure] (remote-name remote) => string[procedure] (remote-name-set! remote name) => void
remote-name returns the name of the given remote, for example "origin".
remote-name-set! changes the name of the given remote to the string name.
On success, the on-disk repository is updated immediately.
[procedure] (remote repository name) => remoteRetrieves the remote of the given name from the repository. An error is signaled if no such remote exists.
[procedure] (remotes repository) => (list-of remote)Returns a list of all remotes in the given repository.
Config
[record] config[procedure] (config? obj) => boolean
A config represents a Git configuration file, associated with either a repository, the current user, or the system-wide Git installation.
[procedure] (config-path [type]) => stringReturns the path to a Git configuration file, if one exists. type may be a symbol specifying the type of path to search, either user, system or xdg, to request the path to the configuration for the current user, the system-wide Git installation, or the configuration file path specified by the XDG standard (".config/git/config"), respectively. type defaults to user. An error is signalled if no configuration file is found at the requested location.
[procedure] (config-open [source]) => configReads the Git configuration file indicated by source, which may be a repository, path, or symbol as expected by config-path. An error is signalled if no configuration file is found at the requested location.
[procedure] (config-get config name [type]) => objectReturns the value of the property name in the given config object. The value is returned as a string, unless an alternative return type is specified by the given symbol type, which should be string, symbol, number or boolean. An error is signaled if the requested property doesn't exist, or if it cannot be converted to the specified return type.
[procedure] (config-set! config name value) => objectSets the value of the property name in the given config object to the given value.
On success, the new value is written immediately to disk.
[procedure] (config-unset! config name) => voidDeletes the property name from the given config object.
On success, the change is written immediately to disk.
History
- 0.1.0
- Initial port to CHICKEN 5.
- 0.1.1
- Fix incorrect handling of create-blob procedure arguments.
- 0.2.0
- Fix memory management issue for public structures in low-level interface.
Author
Evan Hanson
License
Copyright (c) 2013-2021, Evan Hanson, 3-Clause BSD License