Repositories

CLOS class repository
Superclass:

[‘T’]

Metaclass:

standard-class

Repository is the root type, it contains the object database.

Creating

Generic (init-repository path/name &key bare)
(init-repository (path STRING) &KEY BARE)
(init-repository (path PATHNAME) &KEY BARE)

Create a new Git repository. PATH/NAME can be either an instance of a STRING or a PATHNAME. A truthful value for the key BARE will init a repository that does not have a local checkout, it’s normally appropriate for the basename of the path to end in ‘.git’. A REPOSITORY instance is returned.

GIT> (init-repository #p"/tmp/test-repo/")
#<REPOSITORY 7FFFE8006800 {1005F3CE43}>
Generic (empty-p repository)
(empty-p (repository REPOSITORY))

Return T if the repository is empty and contains no references.

GIT> (empty-p (open-repository #p"/tmp/test-repo/"))
T

Bare

Bare repositories can be created by passing a truthful value to the key argument BARE when initialising a repository.

GIT> (init-repository #p"/tmp/test-bare/" :bare t)
#<REPOSITORY 7FFFE8008CD0 {10062DE723}>

Whether an existing repository is bare can be determined using the bare-p method.

Generic (bare-p repository)
(bare-p (repository REPOSITORY))

Return T if the repository is bare.

GIT> (bare-p (open-repository #p"/tmp/test-bare/"))
T

Accessing

Generic (open-repository path/name)
(open-repository (path STRING))
(open-repository (path PATHNAME))

Open an existing repository located at PATH/NAME. The repository object will be garbage collected. If it’s freed explicitly then all related objects will have undefined behaviour.

GIT> (open-repository #p"/home/russell/projects/ecl/")
#<REPOSITORY 7FFFE8003E00 {1004CCDBA3}>
GIT> (open-repository "/home/russell/projects/ecl/")
#<REPOSITORY 7FFFE8004000 {1004D617F3}>
Macro (with-repository (var pathname-or-string) &body body)

Evaluates the body with VAR bound to a newly opened located repository at PATHNAME-OR-STRING. Repository is freed upon exit of this scope so any objects that leave this scope will no longer be able to access the repository.

Parameters:
  • pathname-or-string – the location of the repository.

  • path – the path to the git repository.

  • body – the body of the macro.

CL-GIT> (with-repository (repository #p"/home/russell/projects/ecl/")
          (prin1 repository)
          nil)
#<REPOSITORY 7FFFE8003E00 {1003880DA3}>
NIL

Checkout

Generic (checkout object repository)
(checkout (object REFERENCE) (repository T))
(checkout (object T) (repository T))

Checkout an object and replace the working tree and index with it’s content. If passed a reference update the head ot point at the reference.

Path

Generic (repository-path object)
(repository-path (repository REPOSITORY))

Return the path to the repository. In the case where the repository isn’t bare then it will be the location of the .git directory.

Generic (repository-workdir object)
(repository-workdir (repository REPOSITORY))

Return the path to the root of the repository.

Status

Function (repository-status repository)

Return the current status values for each of the object in the repository. For each element of the list the FIRST is the name of the file and the CDR is a list of keywords that containing the current state of the file. Possible states are: :CURRENT :INDEX-NEW :INDEX-MODIFIED :INDEX-DELETED :INDEX-RENAMED :INDEX-TYPECHANGE :WORKTREE-NEW :WORKTREE-MODIFIED :WORKTREE-DELETED :WORKTREE-TYPECHANGE :WORKTREE-RENAMED :WORKTREE-UNREADABLE :IGNORED or :CONFLICTED

CL-GIT> (with-repository (repository #p"/home/russell/projects/lisp/cl-git/")
           (repository-status repository))

(("src/status.lisp" :CURRENT :WORKTREE-MODIFIED)
 ("src/package.lisp" :CURRENT :WORKTREE-MODIFIED)
 ("fabfile.pyc" :CURRENT :IGNORED)
 ("doc/repositories.rst" :CURRENT :WORKTREE-MODIFIED)
 ("doc/cl-git.html" :CURRENT :WORKTREE-NEW)
 ("doc/.installed.cfg" :CURRENT :IGNORED))

Configuration

Configuration details of a particular repository can be done with the GIT-CONFIG method.

Method (git-config (object REPOSITORY) &key level)

Open a Git config. LEVEL can be used to limit the git config to a specific level. Possible levels are :HIGHEST-LEVEL :SYSTEM :XDG :GLOBAL or :LOCAL

See also: git-config