On this page:
git_  repository_  config
git_  repository_  config_  snapshot
git_  repository_  detach_  head
git_  repository_  discover
git_  repository_  fetchhead_  foreach
git_  repository_  free
git_  repository_  get_  namespace
git_  repository_  hashfile
git_  repository_  head
git_  repository_  head_  detached
git_  repository_  head_  unborn
git_  repository_  ident
git_  repository_  index
git_  repository_  init
git_  repository_  init_  ext
git_  repository_  init_  init_  options
git_  repository_  is_  bare
git_  repository_  is_  empty
git_  repository_  is_  shallow
git_  repository_  mergehead_  foreach
git_  repository_  message
git_  repository_  message_  remove
git_  repository_  new
git_  repository_  odb
git_  repository_  open
git_  repository_  open_  bare
git_  repository_  open_  ext
git_  repository_  path
git_  repository_  refdb
git_  repository_  reinit_  filesystem
git_  repository_  set_  bare
git_  repository_  set_  config
git_  repository_  set_  head
git_  repository_  set_  head_  detached
git_  repository_  set_  head_  detached_  from_  annotated
git_  repository_  set_  ident
git_  repository_  set_  index
git_  repository_  set_  namespace
git_  repository_  set_  odb
git_  repository_  set_  refdb
git_  repository_  set_  workdir
git_  repository_  state
git_  repository_  state_  cleanup
git_  repository_  workdir
git_  repository_  wrap_  odb
8.12

37 Repository🔗ℹ

 (require libgit2/include/repository) package: libgit2

procedure

(git_repository_config repo)  config?

  repo : repository?
Get the configuration file for this repository.

If a configuration file has not been set, the default config set for the repository will be returned, including global and system configurations (if they are available).

The configuration file must be freed once it’s no longer being used by the user.

procedure

(git_repository_config_snapshot repo)  config?

  repo : repository?
Get a snapshot of the repository’s configuration

Convenience function to take a snapshot from the repository’s configuration. The contents of this snapshot will not change, even if the underlying config files are modified.

The configuration file must be freed once it’s no longer being used by the user.

procedure

(git_repository_detach_head repo)  integer?

  repo : repository?
Detach the HEAD.

If the HEAD is already detached and points to a Commit, 0 is returned.

If the HEAD is already detached and points to a Tag, the HEAD is updated into making it point to the peeled Commit, and 0 is returned.

If the HEAD is already detached and points to a non commitish, the HEAD is unaltered, and -1 is returned.

Otherwise, the HEAD will be detached and point to the peeled Commit.

procedure

(git_repository_discover out    
  start_path    
  across_fs    
  ceiling_dirs)  integer?
  out : buf?
  start_path : string?
  across_fs : boolean?
  ceiling_dirs : string?
Look for a git repository and copy its path in the given buffer. The lookup start from base_path and walk across parent directories if nothing has been found. The lookup ends when the first repository is found, or when reaching a directory referenced in ceiling_dirs or when the filesystem changes (in case across_fs is true).

The method will automatically detect if the repository is bare (if there is a repository).

procedure

(git_repository_fetchhead_foreach repo    
  callback    
  payload)  integer?
  repo : repository?
  callback : git_repository_fetchhead_foreach_cb
  payload : bytes?
Invoke ’callback’ for each entry in the given FETCH_HEAD file.

Return a non-zero value from the callback to stop the loop.

procedure

(git_repository_free repo)  void?

  repo : repository?
Free a previously allocated repository

Note that after a repository is free’d, all the objects it has spawned will still exist until they are manually closed by the user with git_object_free, but accessing any of the attributes of an object without a backing repository will result in undefined behavior

procedure

(git_repository_get_namespace repo)  string?

  repo : repository?
Get the currently active namespace for this repository

procedure

(git_repository_hashfile out    
  repo    
  path    
  type    
  as_path)  integer?
  out : oid?
  repo : repository?
  path : string?
  type : git_otype
  as_path : string?
Calculate hash of file using repository filtering rules.

If you simply want to calculate the hash of a file on disk with no filters, you can just use the git_odb_hashfile() API. However, if you want to hash a file in the repository and you want to apply filtering rules (e.g. crlf filters) before generating the SHA, then use this function.

Note: if the repository has core.safecrlf set to fail and the filtering triggers that failure, then this function will return an error and not calculate the hash of the file.

procedure

(git_repository_head repo)  reference?

  repo : repository?
Retrieve and resolve the reference pointed at by HEAD.

The returned git_reference will be owned by caller and git_reference_free() must be called when done with it to release the allocated memory and prevent a leak.

procedure

(git_repository_head_detached repo)  boolean?

  repo : repository?
Check if a repository’s HEAD is detached

A repository’s HEAD is detached when it points directly to a commit instead of a branch.

procedure

(git_repository_head_unborn repo)  boolean?

  repo : repository?
Check if the current branch is unborn

An unborn branch is one named from HEAD but which doesn’t exist in the refs namespace, because it doesn’t have any commit to point to.

procedure

(git_repository_ident repo)  integer?

  repo : repository?
Retrieve the configured identity to use for reflogs

The memory is owned by the repository and must not be freed by the user.

Returns (values (name : string?) (email : string?)). See Multiple Values

procedure

(git_repository_index repo)  index?

  repo : repository?
Get the Index file for this repository.

If a custom index has not been set, the default index for the repository will be returned (the one located in .git/index).

The index must be freed once it’s no longer being used by the user.

procedure

(git_repository_init path is_bare)  repository?

  path : string?
  is_bare : #f
Creates a new Git repository in the given folder.

TODO: - Reinit the repository

procedure

(git_repository_init_ext repo_path opts)  repository?

  repo_path : string?
  opts : git_repository_init_opts?
Create a new Git repository in the given folder with extended controls.

This will initialize a new git repository (creating the repo_path if requested by flags) and working directory as needed. It will auto-detect the case sensitivity of the file system and if the file system supports file mode bits correctly.

procedure

(git_repository_init_init_options opts    
  version)  integer?
  opts : git_repository_init_options?
  version : integer?
Initializes a git_repository_init_options with default values. Equivalent to creating an instance with GIT_REPOSITORY_INIT_OPTIONS_INIT.

procedure

(git_repository_is_bare repo)  boolean?

  repo : repository?
Check if a repository is bare

procedure

(git_repository_is_empty repo)  boolean?

  repo : repository?
Check if a repository is empty

An empty repository has just been initialized and contains no references apart from HEAD, which must be pointing to the unborn master branch.

procedure

(git_repository_is_shallow repo)  boolean?

  repo : repository?
Determine if the repository was a shallow clone

procedure

(git_repository_mergehead_foreach repo    
  callback    
  payload)  integer?
  repo : repository?
  callback : git_repository_mergehead_foreach_cb
  payload : bytes?
If a merge is in progress, invoke ’callback’ for each commit ID in the MERGE_HEAD file.

Return a non-zero value from the callback to stop the loop.

procedure

(git_repository_message out repo)  integer?

  out : buf?
  repo : repository?
Retrieve git’s prepared message

Operations such as git revert/cherry-pick/merge with the -n option stop just short of creating a commit with the changes and save their prepared message in .git/MERGE_MSG so the next git-commit execution can present it to the user for them to amend if they wish.

Use this function to get the contents of this file. Don’t forget to remove the file after you create the commit.

procedure

(git_repository_message_remove repo)  integer?

  repo : repository?
Remove git’s prepared message.

Remove the message that git_repository_message retrieves.

procedure

(git_repository_new)  repository?

Create a new repository with neither backends nor config object

Note that this is only useful if you wish to associate the repository with a non-filesystem-backed object database and config store.

procedure

(git_repository_odb repo)  odb?

  repo : repository?
Get the Object Database for this repository.

If a custom ODB has not been set, the default database for the repository will be returned (the one located in .git/objects).

The ODB must be freed once it’s no longer being used by the user.

procedure

(git_repository_open path)  repository?

  path : string?
Open a git repository.

The ’path’ argument must point to either a git repository folder, or an existing work dir.

The method will automatically detect if ’path’ is a normal or bare repository or fail is ’path’ is neither.

procedure

(git_repository_open_bare bare_path)  repository?

  bare_path : string?
Open a bare repository on the serverside.

This is a fast open for bare repositories that will come in handy if you’re e.g. hosting git repositories and need to access them efficiently

procedure

(git_repository_open_ext path    
  flags    
  ceiling_dirs)  repository?
  path : string?
  flags : integer?
  ceiling_dirs : string?
Find and open a repository with extended controls.

procedure

(git_repository_path repo)  string?

  repo : repository?
Get the path of this repository

This is the path of the .git folder for normal repositories, or of the repository itself for bare repositories.

procedure

(git_repository_refdb repo)  refdb?

  repo : repository?
Get the Reference Database Backend for this repository.

If a custom refsdb has not been set, the default database for the repository will be returned (the one that manipulates loose and packed references in the .git directory).

The refdb must be freed once it’s no longer being used by the user.

procedure

(git_repository_reinit_filesystem repo 
  recurse_submodules) 
  integer?
  repo : repository?
  recurse_submodules : boolean?
Update the filesystem config settings for an open repository

When a repository is initialized, config values are set based on the properties of the filesystem that the repository is on, such as "core.ignorecase", "core.filemode", "core.symlinks", etc. If the repository is moved to a new filesystem, these properties may no longer be correct and API calls may not behave as expected. This call reruns the phase of repository initialization that sets those properties to compensate for the current filesystem of the repo.

procedure

(git_repository_set_bare repo)  integer?

  repo : repository?
Set a repository to be bare.

Clear the working directory and set core.bare to true. You may also want to call git_repository_set_index(repo, NULL) since a bare repo typically does not have an index, but this function will not do that for you.

procedure

(git_repository_set_config repo config)  void?

  repo : repository?
  config : config?
Set the configuration file for this repository

This configuration file will be used for all configuration queries involving this repository.

The repository will keep a reference to the config file; the user must still free the config after setting it to the repository, or it will leak.

procedure

(git_repository_set_head repo refname)  integer?

  repo : repository?
  refname : string?
Make the repository HEAD point to the specified reference.

If the provided reference points to a Tree or a Blob, the HEAD is unaltered and -1 is returned.

If the provided reference points to a branch, the HEAD will point to that branch, staying attached, or become attached if it isn’t yet. If the branch doesn’t exist yet, no error will be return. The HEAD will then be attached to an unborn branch.

Otherwise, the HEAD will be detached and will directly point to the Commit.

procedure

(git_repository_set_head_detached repo    
  commitish)  integer?
  repo : repository?
  commitish : oid?
Make the repository HEAD directly point to the Commit.

If the provided committish cannot be found in the repository, the HEAD is unaltered and GIT_ENOTFOUND is returned.

If the provided commitish cannot be peeled into a commit, the HEAD is unaltered and -1 is returned.

Otherwise, the HEAD will eventually be detached and will directly point to the peeled Commit.

procedure

(git_repository_set_head_detached_from_annotated repo 
  commitish) 
  integer?
  repo : repository?
  commitish : annotated_commit?
Make the repository HEAD directly point to the Commit.

This behaves like git_repository_set_head_detached() but takes an annotated commit, which lets you specify which extended sha syntax string was specified by a user, allowing for more exact reflog messages.

See the documentation for git_repository_set_head_detached().

procedure

(git_repository_set_ident repo name email)  integer?

  repo : repository?
  name : string?
  email : string?
Set the identity to be used for writing reflogs

If both are set, this name and email will be used to write to the reflog. Pass NULL to unset. When unset, the identity will be taken from the repository’s configuration.

procedure

(git_repository_set_index repo index)  void?

  repo : repository?
  index : index?
Set the index file for this repository

This index will be used for all index-related operations involving this repository.

The repository will keep a reference to the index file; the user must still free the index after setting it to the repository, or it will leak.

procedure

(git_repository_set_namespace repo nmspace)  integer?

  repo : repository?
  nmspace : string?
Sets the active namespace for this Git Repository

This namespace affects all reference operations for the repo. See man gitnamespaces

procedure

(git_repository_set_odb repo odb)  void?

  repo : repository?
  odb : odb?
Set the Object Database for this repository

The ODB will be used for all object-related operations involving this repository.

The repository will keep a reference to the ODB; the user must still free the ODB object after setting it to the repository, or it will leak.

procedure

(git_repository_set_refdb repo refdb)  void?

  repo : repository?
  refdb : refdb?
Set the Reference Database Backend for this repository

The refdb will be used for all reference related operations involving this repository.

The repository will keep a reference to the refdb; the user must still free the refdb object after setting it to the repository, or it will leak.

procedure

(git_repository_set_workdir repo    
  workdir    
  update_gitlink)  integer?
  repo : repository?
  workdir : string?
  update_gitlink : boolean?
Set the path to the working directory for this repository

The working directory doesn’t need to be the same one that contains the .git folder for this repository.

If this repository is bare, setting its working directory will turn it into a normal repository, capable of performing all the common workdir operations (checkout, status, index manipulation, etc).

procedure

(git_repository_state repo)  integer?

  repo : repository?
Determines the status of a git repository - ie, whether an operation (merge, cherry-pick, etc) is in progress.

procedure

(git_repository_state_cleanup repo)  integer?

  repo : repository?
Remove all the metadata associated with an ongoing command like merge, revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc.

procedure

(git_repository_workdir repo)  string?

  repo : repository?
Get the path of the working directory for this repository

If the repository is bare, this function will always return NULL.

procedure

(git_repository_wrap_odb odb)  repository?

  odb : odb?
Create a "fake" repository to wrap an object database

Create a repository object to wrap an object database to be used with the API when all you have is an object database. This doesn’t have any paths associated with it, so use with care.