References ========== .. cl:package:: cl-git .. cl:clos-class:: reference Creating -------- .. cl:method:: make-object (eq reference) common-lisp:t common-lisp:t Accessing --------- To access a single reference get object can be used, but the fully qualified name of the reference must be specified. .. cl:method:: get-object (eq reference) common-lisp:t common-lisp:t .. code-block:: common-lisp-repl GIT> (get-object 'reference "refs/heads/master" (open-repository (merge-pathnames #p"projects/lisp/cl-git" (user-homedir-pathname)))) # Details ~~~~~~~ .. cl:method:: full-name reference .. code-block:: common-lisp-repl GIT> (full-name (get-object 'reference "refs/heads/master" (open-repository (merge-pathnames #p"projects/lisp/cl-git" (user-homedir-pathname))))) "refs/heads/master" .. cl:method:: short-name reference .. code-block:: common-lisp-repl GIT> (short-name (get-object 'reference "refs/heads/master" (open-repository (merge-pathnames #p"projects/lisp/cl-git" (user-homedir-pathname))))) "master" Listing ~~~~~~~ .. cl:method:: list-objects (eq reference) common-lisp:t To list all the references present in a repository we use the function :cl:symbol:`LIST-OBJECTS` and tell to only list objects of type :cl:symbol:`REFERENCE`. .. code-block:: common-lisp-repl GIT> (list-objects 'reference (open-repository "/home/russell/projects/lisp/cl-git/")) (# # # # # # #) Filtering Results ^^^^^^^^^^^^^^^^^ .. cl:generic:: branch-p reference .. code-block:: common-lisp-repl GIT> (list-objects 'reference repo :test #'branch-p) (# #) .. cl:generic:: symbolic-p reference .. code-block:: common-lisp-repl GIT> (list-objects 'reference repo :test #'symbolic-p) (#) .. cl:generic:: remote-p reference .. code-block:: common-lisp-repl GIT> (list-objects 'reference repo :test #'remote-p) (# # # #) .. cl:generic:: head-p reference .. code-block:: common-lisp-repl GIT> (list-objects 'reference repo :test #'head-p) (#) Resolving ~~~~~~~~~ .. cl:generic:: target reference .. code-block:: common-lisp-repl GIT> (target (get-object 'reference "HEAD" (open-repository (merge-pathnames #p"projects/ecl" (user-homedir-pathname))))) # .. cl:generic:: resolve reference .. code-block:: common-lisp-repl GIT> (resolve (get-object 'reference "HEAD" (open-repository (merge-pathnames #p"projects/ecl" (user-homedir-pathname))))) # (# #) Branches ~~~~~~~~ In libgit2 and in cl-git, branches are references but in a different namespace. Which means that, the same function used to list references is used to list branches. To limit the references to branches only use :cl:symbol:`~BRANCH-P`. .. cl:generic:: branch-p reference .. code-block:: common-lisp-repl GIT> (list-objects 'reference repo :test #'branch-p) (# #) So a branch is a special kind of reference. In git there are a few differences between branches and references: - branches are stored in a special location in the .git folder - branches are moved/updated during a git commit operation For a user of the git repository, this small difference between branches and normal references makes a huge difference. You commit on branches and merge different branches. But typically you will not deal with non branch references. Listing remote branches can be done with. .. code-block:: common-lisp-repl GIT> (list-objects 'reference (open-repository #p"/home/russell/projects/ecl/") :test #'remote-p) (# #)