Show / Hide Table of Contents

Class libgit2

The native libgit2 functions. Upon the first invocation of any of these functions, the native library will be loaded and the git_libgit2_init() function will be called to set up the native library.

Inheritance
System.Object
libgit2
Namespace: Dogged.Native
Assembly: Dogged.Native.dll
Syntax
public static class libgit2 : object

Methods

git_blob_filter(git_buf, git_blob*, String, git_blob_filter_options*)

Declaration
public static extern int git_blob_filter(git_buf content, git_blob*blob, string path, git_blob_filter_options*options)
Parameters
Type Name Description
git_buf content
git_blob* blob
System.String path
git_blob_filter_options* options
Returns
Type Description
System.Int32

git_blob_is_binary(git_blob*)

Declaration
public static extern int git_blob_is_binary(git_blob*blob)
Parameters
Type Name Description
git_blob* blob
Returns
Type Description
System.Int32

git_blob_lookup(out git_blob*, git_repository*, ref git_oid)

Look up a blob from the repository.

Declaration
public static extern int git_blob_lookup(out git_blob*blob, git_repository*repo, ref git_oid id)
Parameters
Type Name Description
git_blob* blob

Pointer to the blob that was loaded from the repository

git_repository* repo

The repository that contains the blob

git_oid id

The id of the blob to lookup

Returns
Type Description
System.Int32

0 on success or an error code

git_blob_rawcontent(git_blob*)

Declaration
public static extern byte *git_blob_rawcontent(git_blob*blob)
Parameters
Type Name Description
git_blob* blob
Returns
Type Description
System.Byte*

git_blob_rawsize(git_blob*)

Get the size in bytes of the contents of a blob.

Declaration
public static extern long git_blob_rawsize(git_blob*blob)
Parameters
Type Name Description
git_blob* blob

The blob to examine

Returns
Type Description
System.Int64

Raw size of the blob in bytes

git_buf_dispose(git_buf)

Declaration
public static extern void git_buf_dispose(git_buf buf)
Parameters
Type Name Description
git_buf buf

git_clone(out git_repository*, String, String, git_clone_options*)

Clone a remote repository.

By default this creates its repository and initial remote to match git's defaults. You can use the options in the callback to customize how these are created.

Declaration
public static extern int git_clone(out git_repository*repo, string remotePath, string localPath, git_clone_options*options)
Parameters
Type Name Description
git_repository* repo

Pointer to the repository that will be cloned.

System.String remotePath

The remote repository to clone

System.String localPath

The local path to clone to

git_clone_options* options

Configuration options for the clone. If null, defaults will be used.

Returns
Type Description
System.Int32

0 on success or an error code

git_commit_author(git_commit*)

Get the signature for the commit's author. This data is owned by the commit and should not be freed.

Declaration
public static extern git_signature*git_commit_author(git_commit*commit)
Parameters
Type Name Description
git_commit* commit

The commit to examine

Returns
Type Description
git_signature*

A pointer to a signature for the author

git_commit_committer(git_commit*)

Get the signature for the commit's committer. This data is owned by the commit and should not be freed.

Declaration
public static extern git_signature*git_commit_committer(git_commit*commit)
Parameters
Type Name Description
git_commit* commit

The commit to examine

Returns
Type Description
git_signature*

A pointer to a signature for the committer

git_commit_lookup(out git_commit*, git_repository*, ref git_oid)

Look up a commit from the repository.

Declaration
public static extern int git_commit_lookup(out git_commit*obj, git_repository*repo, ref git_oid id)
Parameters
Type Name Description
git_commit* obj

Pointer to the commit that was loaded from the repository

git_repository* repo

The repository that contains the commit

git_oid id

The id of the commit to lookup

Returns
Type Description
System.Int32

0 on success or an error code

git_commit_tree(out git_tree*, git_commit*)

Get the tree that the given commit points to. This tree must be freed when it is no longer needed.

Declaration
public static extern int git_commit_tree(out git_tree*tree, git_commit*commit)
Parameters
Type Name Description
git_tree* tree

A pointer to the tree

git_commit* commit

The commit to examine

Returns
Type Description
System.Int32

0 on success or an error code

git_commit_tree_id(git_commit*)

Get the object id of the tree that the given commit points to. This differs from git_commit_tree(out git_tree*, git_commit*) in that no attempts are made to lookup the tree or validate it.

Declaration
public static extern git_oid*git_commit_tree_id(git_commit*commit)
Parameters
Type Name Description
git_commit* commit

The commit to examine

Returns
Type Description
git_oid*

A pointer to the tree's object id

git_error_last()

Returns the information (class and message) for the last error that occurred on the current thread. This information is undefined if the last libgit2 function did not return an error.

Declaration
public static extern git_error*git_error_last()
Returns
Type Description
git_error*

A pointer to a git_error that describes the error.

git_filter_list_apply_to_blob(git_buf, git_filter_list*, git_blob*)

Apply a filter list to the contents of a blob.

Declaration
public static extern int git_filter_list_apply_to_blob(git_buf outputBuffer, git_filter_list*filters, git_blob*blob)
Parameters
Type Name Description
git_buf outputBuffer

Buffer to store the result of the filtering

git_filter_list* filters

A loaded git_filter_list (or null)

git_blob* blob

The blob to filter

Returns
Type Description
System.Int32

git_filter_list_apply_to_data(git_buf, git_filter_list*, git_buf)

Apply filter list to a data buffer.

If the `inputBuffer` buffer holds data allocated by libgit2 (i.e. `inputBuffer->asize` is not zero), then it will be overwritten when applying the filters. If not, then it will be left untouched.

If there are no filters to apply (or `filters` is NULL), then the `outputBuffer` buffer will reference the `inputBuffer` buffer data (with `asize` set to zero) instead of allocating data. This keeps allocations to a minimum, but it means you have to be careful about freeing the `inputBuffer` data since `outputBuffer` may be pointing to it!

Declaration
public static extern int git_filter_list_apply_to_data(git_buf outputBuffer, git_filter_list*filters, git_buf inputBuffer)
Parameters
Type Name Description
git_buf outputBuffer

Buffer to store the result of the filtering

git_filter_list* filters

A loaded git_filter_list (or null)

git_buf inputBuffer

Buffer containing the data to filter

Returns
Type Description
System.Int32

0 on success or an error code

git_filter_list_apply_to_file(git_buf, git_filter_list*, git_repository*, String)

Apply a filter list to the contents of a file on disk.

Declaration
public static extern int git_filter_list_apply_to_file(git_buf outputBuffer, git_filter_list*filters, git_repository*repo, string path)
Parameters
Type Name Description
git_buf outputBuffer

Buffer to store the result of the filtering

git_filter_list* filters

A loaded git_filter_list (or null)

git_repository* repo

The repository to perform the filtering in

System.String path

The path of the file to filter; a relative path will be taken as relative to the workdir

Returns
Type Description
System.Int32

git_filter_list_free(git_filter_list*)

Free a git filter list.

Declaration
public static extern void git_filter_list_free(git_filter_list*filters)
Parameters
Type Name Description
git_filter_list* filters

The filter list to free

git_filter_list_load(out git_filter_list*, git_repository*, git_blob*, String, git_filter_mode_t, UInt32)

Load the filter list for a given path.

This will return 0 (success) but set the output git_filter_list to NULL if no filters are requested for the given file.

Declaration
public static extern int git_filter_list_load(out git_filter_list*filters, git_repository*repo, git_blob*blob, string path, git_filter_mode_t mode, uint flags)
Parameters
Type Name Description
git_filter_list* filters

Output newly created git_filter_list (or NULL)

git_repository* repo

Repository object that contains path

git_blob* blob

The blob to which the filter will be applied (if known)

System.String path

Relative path of the file to be filtered

git_filter_mode_t mode

Filtering direction (WT->ODB or ODB->WT)

System.UInt32 flags

Combination of git_filter_flag_t flags

Returns
Type Description
System.Int32

0 on success (which could still return NULL if no filters are needed for the requested file) or an error code

git_filter_list_load_ext(out git_filter_list*, git_repository*, git_blob*, String, git_filter_mode_t, ref git_filter_options)

Load the filter list for a given path.

This will return 0 (success) but set the output git_filter_list to NULL if no filters are requested for the given file.

Declaration
public static extern int git_filter_list_load_ext(out git_filter_list*filters, git_repository*repo, git_blob*blob, string path, git_filter_mode_t mode, ref git_filter_options opts)
Parameters
Type Name Description
git_filter_list* filters

Output newly created git_filter_list (or NULL)

git_repository* repo

Repository object that contains path

git_blob* blob

The blob to which the filter will be applied (if known)

System.String path

Relative path of the file to be filtered

git_filter_mode_t mode

Filtering direction (WT->ODB or ODB->WT)

git_filter_options opts
Returns
Type Description
System.Int32

0 on success (which could still return NULL if no filters are needed for the requested file) or an error code

git_index_entrycount(git_index*)

Get the count of entries currently in the index.

Declaration
public static extern UIntPtr git_index_entrycount(git_index*index)
Parameters
Type Name Description
git_index* index

The index to read the entry from

Returns
Type Description
UIntPtr

Count of the current entries

git_index_free(git_index*)

Free an existing index object.

Declaration
public static extern void git_index_free(git_index*index)
Parameters
Type Name Description
git_index* index

The index to free

git_index_get_byindex(git_index*, UIntPtr)

Get a pointer to an entry in the index at the the given position.

The entry is not modifiable and should not be freed. Because the `git_index_entry` struct is a publicly defined struct, you should be able to make your own permanent copy of the data if necessary.

Declaration
public static extern git_index_entry*git_index_get_byindex(git_index*index, UIntPtr n)
Parameters
Type Name Description
git_index* index

The index to read the entry from

UIntPtr n

The position of the index entry

Returns
Type Description
git_index_entry*

A pointer to the entry or NULL if out of bounds

git_index_get_bypath(git_index*, String, Int32)

Get a pointer to an entry in the index for the given path at the given stage level.

A "stage level" is a construct for handling conflicted files during a merge; generally, files are in stage level 0 (sometimes called the "main index"); if a file is in conflict after a merge, there will be no entry at stage level 0, instead there will be entries at stages 1-3 representing the conflicting contents of the common ancestor, the file in "our" branch and the file in "their" branch.

The entry is not modifiable and should not be freed. Because the `git_index_entry` struct is a publicly defined struct, you should be able to make your own permanent copy of the data if necessary.

Declaration
public static extern git_index_entry*git_index_get_bypath(git_index*index, string path, int stage)
Parameters
Type Name Description
git_index* index

The index to read the entry from

System.String path

The path for the index entry

System.Int32 stage

The stage level to query

Returns
Type Description
git_index_entry*

A pointer to the entry or NULL if out of bounds

git_index_iterator_free(git_index_iterator*)

Free an existing index iterator.

Declaration
public static extern void git_index_iterator_free(git_index_iterator*iterator)
Parameters
Type Name Description
git_index_iterator* iterator

The iterator to free

git_index_iterator_new(out git_index_iterator*, git_index*)

Create a new index iterator; this will take a snapshot of the given index for iteration.

Declaration
public static extern int git_index_iterator_new(out git_index_iterator*iterator, git_index*index)
Parameters
Type Name Description
git_index_iterator* iterator

Pointer to the iterator that was created

git_index* index

The index to iterate over

Returns
Type Description
System.Int32

0 on success or an error code

git_index_iterator_next(out git_index_entry*, git_index_iterator*)

Get the next index entry in the iterator. This entry is owned by the iterator and should not be freed.

Declaration
public static extern int git_index_iterator_next(out git_index_entry*entry, git_index_iterator*iterator)
Parameters
Type Name Description
git_index_entry* entry

Pointer to the entry in the index

git_index_iterator* iterator

The iterator to query

Returns
Type Description
System.Int32

0 on success, GIT_ITEROVER on successful completion of iteration, or an error code

git_libgit2_features()

Query compile time options for libgit2. This will show the functionality that is built in to the library.

Declaration
public static extern git_feature_t git_libgit2_features()
Returns
Type Description
git_feature_t

A combination of git_feature_t values.

git_libgit2_init()

Initialize the native library's global state.

This function must be called before any other libgit2 function in order to set up global state and threading.

This function may be called multiple times - it will return the number of times the initialization has been called (including this one) that have not subsequently been shutdown.

Declaration
public static extern int git_libgit2_init()
Returns
Type Description
System.Int32

The number of initializations of the library, or an error code.

git_libgit2_opts(git_libgit2_opt_t, git_config_level_t, git_buf)

Get or set a global configuration option for libgit2.

Declaration
public static extern int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, git_buf buf)
Parameters
Type Name Description
git_libgit2_opt_t option

The option value to get or set

git_config_level_t level
git_buf buf
Returns
Type Description
System.Int32

0 on success or an error code

git_libgit2_opts(git_libgit2_opt_t, git_config_level_t, String)

Declaration
public static extern int git_libgit2_opts(git_libgit2_opt_t option, git_config_level_t level, string path)
Parameters
Type Name Description
git_libgit2_opt_t option
git_config_level_t level
System.String path
Returns
Type Description
System.Int32

git_libgit2_shutdown()

Shutdown the global state.

Clean up the global state and threading context after calling it as many times as git_libgit2_init() was called - it will return the number of remainining initializations that have not been shutdown (after this one).

Declaration
public static extern int git_libgit2_shutdown()
Returns
Type Description
System.Int32

The number of remaining initializations of the library, or an error code.

git_object_dup(out git_object*, git_object*)

Create an in-memory copy of a Git object. This copy must be explicitly free'd or it will leak.

Declaration
public static extern int git_object_dup(out git_object*dest, git_object*source)
Parameters
Type Name Description
git_object* dest

Pointer to store the copy of the object

git_object* source

Original object to copy

Returns
Type Description
System.Int32

0 on success or an error code

git_object_free(git_object*)

Free a git object.

Declaration
public static extern void git_object_free(git_object*obj)
Parameters
Type Name Description
git_object* obj

The object to free

git_object_id(git_object*)

Gets the object id of the given object.

Declaration
public static extern git_oid*git_object_id(git_object*obj)
Parameters
Type Name Description
git_object* obj

The object to examine

Returns
Type Description
git_oid*

A pointer to the object's id

git_object_lookup(out git_object*, git_repository*, ref git_oid, git_object_t)

Look up an object from the repository.

Declaration
public static extern int git_object_lookup(out git_object*obj, git_repository*repo, ref git_oid id, git_object_t type)
Parameters
Type Name Description
git_object* obj

Pointer to the object that was loaded from the repository

git_repository* repo

The repository that contains the object

git_oid id

The id of the object to lookup

git_object_t type

The type of the object to lookup

Returns
Type Description
System.Int32

0 on success or an error code

git_object_type(git_object*)

Get the type of an object.

Declaration
public static extern git_object_t git_object_type(git_object*obj)
Parameters
Type Name Description
git_object* obj

The object to query

Returns
Type Description
git_object_t

The type of the object

git_odb_add_backend(git_odb*, git_odb_backend*, Int32)

Add a custom backend to an existing object database.

The backends are checked in relative ordering, based on the value of the `priority` parameter.

Declaration
public static extern int git_odb_add_backend(git_odb*odb, git_odb_backend*backend, int priority)
Parameters
Type Name Description
git_odb* odb

Database to add the backend to

git_odb_backend* backend

The object database backend to add

System.Int32 priority

Value for ordering the backends queue

Returns
Type Description
System.Int32

0 on success or an error code.

git_odb_backend_loose(out git_odb_backend*, String, Int32, Int32, UInt32, UInt32)

Create a backend for loose object files stored within a typical git object directory containing a "fanout" of subdirectories, named with the first two characters of the object's ID and objects stored in files beneath that, each named with the remaining 38 characters of their ID.

Declaration
public static extern int git_odb_backend_loose(out git_odb_backend*backend, string objects_dir, int compression_level, int do_fsync, uint dir_mode, uint file_mode)
Parameters
Type Name Description
git_odb_backend* backend

Pointer to the odb backend that will be created.

System.String objects_dir

The path to the directory containing packfiles

System.Int32 compression_level

zlib compression level to use

System.Int32 do_fsync

If non-zero, call fsync after writing

System.UInt32 dir_mode

POSIX open(2)-style permissions to use creating a directory or 0 for defaults

System.UInt32 file_mode

POSIX open(2)-style permissions to use creating a file or 0 for defaults

Returns
Type Description
System.Int32

0 on success or an error code.

git_odb_backend_one_pack(out git_odb_backend*, String)

Create a backend out of a single packfile. This can be useful for inspecting the contents of a single packfile.

Declaration
public static extern int git_odb_backend_one_pack(out git_odb_backend*backend, string index_file)
Parameters
Type Name Description
git_odb_backend* backend

Pointer to the odb backend that will be created.

System.String index_file

The path to the packfile's .idx file

Returns
Type Description
System.Int32

0 on success or an error code.

git_odb_backend_pack(out git_odb_backend*, String)

Create a backend for packfiles within a typical git object directory that contains a "pack" directory that will be consulted to find the packfiles to load. Each packfile within that "pack" directory will be consulted as storage for the object database.

Declaration
public static extern int git_odb_backend_pack(out git_odb_backend*backend, string objects_dir)
Parameters
Type Name Description
git_odb_backend* backend

Pointer to the odb backend that will be created.

System.String objects_dir

The path to the directory containing packfiles

Returns
Type Description
System.Int32

0 on success or an error code.

git_odb_foreach(git_odb*, git_odb_foreach_cb, IntPtr)

List all objects available in the database.

The callback will be called for each object available in the database. Note that the objects are likely to be returned in the index order, which would make accessing the objects in that order inefficient. Return a non-zero value from the callback to stop looping.

Declaration
public static extern int git_odb_foreach(git_odb*odb, git_odb_foreach_cb cb, IntPtr payload)
Parameters
Type Name Description
git_odb* odb

The database to iterate.

git_odb_foreach_cb cb

The callback to invoke for each object

IntPtr payload

Custom data to pass back to the callback

Returns
Type Description
System.Int32

0 on success, non-zero callback return value, or error code

git_odb_free(git_odb*)

Close an open database object.

Declaration
public static extern void git_odb_free(git_odb*odb)
Parameters
Type Name Description
git_odb* odb

The database to close. If null, no action is taken.

git_odb_new(out git_odb*)

Create a new object database with no backends.

Before the ODB can be used for read/writing, a custom database backend must be manually added using `git_odb_add_backend()`

Declaration
public static extern int git_odb_new(out git_odb*odb)
Parameters
Type Name Description
git_odb* odb

Pointer to the object database that will be created.

Returns
Type Description
System.Int32

0 on success or an error code.

git_odb_object_data(git_odb_object*)

Return the data of an ODB object. This is the uncompressed, raw data as read from the ODB, without the leading header.

Declaration
public static extern byte *git_odb_object_data(git_odb_object*obj)
Parameters
Type Name Description
git_odb_object* obj

The object to read its contents

Returns
Type Description
System.Byte*

The raw content of the object

git_odb_object_free(git_odb_object*)

Free an ODB object. This method must always be called once a git_odb_object is no longer needed, otherwise memory will leak.

Declaration
public static extern void git_odb_object_free(git_odb_object*obj)
Parameters
Type Name Description
git_odb_object* obj

Object to close

git_odb_object_id(git_odb_object*)

Declaration
public static extern git_oid*git_odb_object_id(git_odb_object*obj)
Parameters
Type Name Description
git_odb_object* obj
Returns
Type Description
git_oid*

git_odb_object_size(git_odb_object*)

Return the size of an ODB object. This is the real size of the data buffer, not the actual size of the object.

Declaration
public static extern UIntPtr git_odb_object_size(git_odb_object*obj)
Parameters
Type Name Description
git_odb_object* obj

The object to query

Returns
Type Description
UIntPtr

The size of the object

git_odb_object_type(git_odb_object*)

Return the type of an ODB object.

Declaration
public static extern git_object_t git_odb_object_type(git_odb_object*obj)
Parameters
Type Name Description
git_odb_object* obj

The object to query

Returns
Type Description
git_object_t

The type of object

git_odb_read(out git_odb_object*, git_odb*, ref git_oid)

Read an object from the database.

This method queries all available ODB backends trying to read the given OID.

Declaration
public static extern int git_odb_read(out git_odb_object*obj, git_odb*odb, ref git_oid id)
Parameters
Type Name Description
git_odb_object* obj

Point to store the read object

git_odb* odb

The database to read from

git_oid id

The object ID to read

Returns
Type Description
System.Int32

0 on success or an error code

git_odb_read_header(out UIntPtr, out git_object_t, git_odb*, ref git_oid)

Read the header of an object from the database, without reading its full contents.

The header includes the length and the type of an object.

Note that most backends do not support reading only the header of an object, so the whole object will be read and then the header will be returned.

Declaration
public static extern int git_odb_read_header(out UIntPtr len_out, out git_object_t type, git_odb*odb, ref git_oid id)
Parameters
Type Name Description
UIntPtr len_out

Pointer to store the length

git_object_t type
git_odb* odb

Database to search for the object in

git_oid id

ID of the objecft to read

Returns
Type Description
System.Int32

0 on success, GIT_ENOTFOUND if the object is not in the database, or an error code

git_odb_write(ref git_oid, git_odb*, Byte*, UIntPtr, git_object_t)

Write an object directly into the object database.

This method writes a full object straight into the ODB. For most cases, it is preferred to write objects through a write stream, which is both faster and less memory intensive, specially for big objects.

This method is provided for compatibility with custom backends which are not able to support streaming writes

Declaration
public static extern int git_odb_write(ref git_oid id, git_odb*odb, byte *data, UIntPtr len, git_object_t type)
Parameters
Type Name Description
git_oid id

Pointer to store the OID result of the write

git_odb* odb

Object database to store the object

System.Byte* data

Buffer with the data to store

UIntPtr len

Size of the buffer

git_object_t type

Type of the data to store

Returns
Type Description
System.Int32

0 on success or an error code

git_oid_cpy(ref git_oid, ref git_oid)

Copy an oid from one structure to another.

Declaration
public static extern int git_oid_cpy(ref git_oid dst, ref git_oid src)
Parameters
Type Name Description
git_oid dst

The oid structure the result is written into.

git_oid src

The oid structure to copy from.

Returns
Type Description
System.Int32

0 on success or error code

git_reference_free(git_reference*)

Free the given reference.

Declaration
public static extern void git_reference_free(git_reference*reference)
Parameters
Type Name Description
git_reference* reference

The reference to free

git_reference_iterator_free(git_reference_iterator*)

Free the given reference iterator.

Declaration
public static extern void git_reference_iterator_free(git_reference_iterator*iterator)
Parameters
Type Name Description
git_reference_iterator* iterator

The iterator to free

git_reference_iterator_new(out git_reference_iterator*, git_repository*)

Create an iterator for the repository's references.

Declaration
public static extern int git_reference_iterator_new(out git_reference_iterator*iterator, git_repository*repository)
Parameters
Type Name Description
git_reference_iterator* iterator

Pointer to the iterator that was created

git_repository* repository
Returns
Type Description
System.Int32

0 on success or an error code

git_reference_lookup(out git_reference*, git_repository*, String)

Lookup a reference by name in a repository. The returned reference must be freed by the user.

Declaration
public static extern int git_reference_lookup(out git_reference*reference, git_repository*repo, string name)
Parameters
Type Name Description
git_reference* reference

Pointer to the reference that was loaded from the repository

git_repository* repo

The repository that contains the reference

System.String name

The name of the reference to lookup

Returns
Type Description
System.Int32

0 on success, GIT_ENOTFOUND if no reference exists by that name, GIT_EINVALIDSPEC if the given name is invalid or an error code

git_reference_name(git_reference*)

Get the full name of a reference.

Declaration
public static extern string git_reference_name(git_reference*reference)
Parameters
Type Name Description
git_reference* reference

The reference to get the name of

Returns
Type Description
System.String

The full name of the reference

git_reference_next(out git_reference*, git_reference_iterator*)

Get the next reference from the iterator.

Declaration
public static extern int git_reference_next(out git_reference*reference, git_reference_iterator*iterator)
Parameters
Type Name Description
git_reference* reference

Pointer to the reference that is next in iteration

git_reference_iterator* iterator

The iterator for the repository's references

Returns
Type Description
System.Int32

0 on success or an error code

git_reference_peel(out git_object*, git_reference*, git_object_t)

Recursively peel reference until object of the specified type is found.

Declaration
public static extern int git_reference_peel(out git_object*obj, git_reference*reference, git_object_t type)
Parameters
Type Name Description
git_object* obj

Pointer to the object that was peeled

git_reference* reference

The reference to peel

git_object_t type

The type of object to peel to

Returns
Type Description
System.Int32

0 on success or an error code

git_reference_symbolic_target(git_reference*)

Get the full name of the target of this reference. This function is only supported for symbolic references.

Declaration
public static extern string git_reference_symbolic_target(git_reference*reference)
Parameters
Type Name Description
git_reference* reference

The reference to get the target of

Returns
Type Description
System.String

The target of the reference or NULL if the reference is not symbolic

git_reference_target(git_reference*)

Get the oid target of this reference. This function is only supported for direct references.

Declaration
public static extern git_oid*git_reference_target(git_reference*reference)
Parameters
Type Name Description
git_reference* reference

The reference to get the target of

Returns
Type Description
git_oid*

The target of the reference or NULL if the reference is not direct

git_reference_type(git_reference*)

Get the type of this reference.

Declaration
public static extern git_reference_t git_reference_type(git_reference*reference)
Parameters
Type Name Description
git_reference* reference

The reference to get the type of

Returns
Type Description
git_reference_t

The type of the reference

git_repository_discover(git_buf, String, Int32, String)

Declaration
public static extern int git_repository_discover(git_buf path, string start_path, int across_fs, string ceiling_dirs)
Parameters
Type Name Description
git_buf path
System.String start_path
System.Int32 across_fs
System.String ceiling_dirs
Returns
Type Description
System.Int32

git_repository_free(git_repository*)

Close a previously opened repository and free any native memory that was allocated.

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.

Declaration
public static extern void git_repository_free(git_repository*repo)
Parameters
Type Name Description
git_repository* repo

The repository handle to close.

git_repository_head(out git_reference*, git_repository*)

Retrieve and resolve the reference pointed to by HEAD.

The returned git_reference will be owned by the caller and git_reference_free(git_reference*) must be called when done to release the allocated memory.

Declaration
public static extern int git_repository_head(out git_reference*reference, git_repository*repo)
Parameters
Type Name Description
git_reference* reference

Pointer to the reference that will be retrieved

git_repository* repo

The repository object

Returns
Type Description
System.Int32

git_repository_head_detached(git_repository*)

Indicates if the repository's HEAD is detached. A repository's HEAD is detached when it points directly to a commit instead of a branch.

Declaration
public static extern int git_repository_head_detached(git_repository*repo)
Parameters
Type Name Description
git_repository* repo

The repository object

Returns
Type Description
System.Int32

1 if the HEAD is detached, 0 if it's not, or an error code

git_repository_index(out git_index*, git_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.

Declaration
public static extern int git_repository_index(out git_index*index, git_repository*repo)
Parameters
Type Name Description
git_index* index

Pointer to the index that will be opened

git_repository* repo

The repository object

Returns
Type Description
System.Int32

0 on success or an error code

git_repository_init(out git_repository*, String, UInt32)

Creates a new Git repository in the given folder.

Declaration
public static extern int git_repository_init(out git_repository*repo, string path, uint bare)
Parameters
Type Name Description
git_repository* repo

Pointer to the repository that will be created.

System.String path

The path to the repository

System.UInt32 bare

If non-zero, a Git repository without a working directory is created at the given path. If zero, the provided path will be considered as the working directory into which the .git directory will be created.

Returns
Type Description
System.Int32

0 on success or an error code.

git_repository_is_bare(git_repository*)

Checks if a repository is bare.

Declaration
public static extern int git_repository_is_bare(git_repository*repo)
Parameters
Type Name Description
git_repository* repo

Repository to test

Returns
Type Description
System.Int32

1 if the repository is bare, 0 otherwise

git_repository_new(out git_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.

Declaration
public static extern int git_repository_new(out git_repository*repo)
Parameters
Type Name Description
git_repository* repo

Pointer to the repository that will be created.

Returns
Type Description
System.Int32

0 on success or an error code.

git_repository_odb(out git_odb*, git_repository*)

Get the object database ("ODB") 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.

Declaration
public static extern int git_repository_odb(out git_odb*odb, git_repository*repo)
Parameters
Type Name Description
git_odb* odb

Pointer to store the loaded ODB

git_repository* repo

A repository object

Returns
Type Description
System.Int32

0 on success or an error code

git_repository_open(out git_repository*, String)

Open a git repository.

The path argument must point to either a Git repository folder, or an existing working tree.

The method will automatically detect if path is a working tree or a bare repository. It will fail if the given path is neither.

Declaration
public static extern int git_repository_open(out git_repository*repo, string path)
Parameters
Type Name Description
git_repository* repo

Pointer to the repository that will be opened.

System.String path

The path to the repository

Returns
Type Description
System.Int32

0 on success or an error code.

git_repository_path(git_repository*)

Declaration
public static extern string git_repository_path(git_repository*repository)
Parameters
Type Name Description
git_repository* repository
Returns
Type Description
System.String

git_repository_set_odb(git_repository*, git_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.

Declaration
public static extern void git_repository_set_odb(git_repository*repo, git_odb*odb)
Parameters
Type Name Description
git_repository* repo

The repository to configure

git_odb* odb

The object database to set

git_repository_workdir(git_repository*)

Declaration
public static extern string git_repository_workdir(git_repository*repository)
Parameters
Type Name Description
git_repository* repository
Returns
Type Description
System.String

git_revparse(git_revspec, git_repository*, String)

Parse a revision string for from, to, and intent.

See `man gitrevisions` or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for information on the syntax accepted.

The contents of the revspec object must be freed by the user.

Pointer to an user-allocated git_revspec struct where the result of the rev-parse will be stored the repository to search in the revision spec to parse
Declaration
public static extern int git_revparse(git_revspec revspec, git_repository*repo, string spec)
Parameters
Type Name Description
git_revspec revspec
git_repository* repo
System.String spec
Returns
Type Description
System.Int32

0 on success, GIT_INVALIDSPEC, GIT_ENOTFOUND, GIT_EAMBIGUOUS or an error code

git_tree_entry_byindex(git_tree*, UIntPtr)

Get a pointer to an entry in the tree at the the given index.

The entry is not modifiable and should not be freed; it will be freed when the owning tree is freed.

Declaration
public static extern git_tree_entry*git_tree_entry_byindex(git_tree*tree, UIntPtr n)
Parameters
Type Name Description
git_tree* tree

The tree to query

UIntPtr n

The index in the tree to return

Returns
Type Description
git_tree_entry*

A tree entry for the given index

git_tree_entry_byname(git_tree*, String)

Get a pointer to an entry in the tree for the the given filename.

The entry is not modifiable and should not be freed; it will be freed when the owning tree is freed.

Declaration
public static extern git_tree_entry*git_tree_entry_byname(git_tree*tree, string filename)
Parameters
Type Name Description
git_tree* tree

The tree to query

System.String filename

The filename in the tree to return

Returns
Type Description
git_tree_entry*

A tree entry for the given index

git_tree_entry_filemode(git_tree_entry*)

Get the file mode of the given tree entry.

Declaration
public static extern uint git_tree_entry_filemode(git_tree_entry*entry)
Parameters
Type Name Description
git_tree_entry* entry

The tree entry to query

Returns
Type Description
System.UInt32

The file mode of the tree entry

git_tree_entry_id(git_tree_entry*)

Get the object id of the given tree entry.

Declaration
public static extern git_oid*git_tree_entry_id(git_tree_entry*entry)
Parameters
Type Name Description
git_tree_entry* entry

The tree entry to query

Returns
Type Description
git_oid*

The object id of the tree entry

git_tree_entry_name(git_tree_entry*)

Get the filename of the given tree entry.

Declaration
public static extern string git_tree_entry_name(git_tree_entry*entry)
Parameters
Type Name Description
git_tree_entry* entry

The tree entry to query

Returns
Type Description
System.String

The filename of the tree entry

git_tree_entrycount(git_tree*)

Get the number of entries in the tree.

Declaration
public static extern UIntPtr git_tree_entrycount(git_tree*tree)
Parameters
Type Name Description
git_tree* tree

The tree to query

Returns
Type Description
UIntPtr

The number of entries in the tree

git_tree_lookup(out git_tree*, git_repository*, ref git_oid)

Look up a tree from the repository.

Declaration
public static extern int git_tree_lookup(out git_tree*obj, git_repository*repo, ref git_oid id)
Parameters
Type Name Description
git_tree* obj

Pointer to the tree that was loaded from the repository

git_repository* repo

The repository that contains the tree

git_oid id

The id of the tree to lookup

Returns
Type Description
System.Int32

0 on success or an error code

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX