Skip to content

cvedia::rt::GitAPI

More...

#include <gitapi.h>

Public Functions

Name
GitAPI()
~GitAPI()
GitAPI(GitAPI const & ) =delete
GitAPI & operator=(GitAPI const & ) =delete
GitAPI(GitAPI && ) =delete
GitAPI & operator=(GitAPI && ) =delete
NODISCARD expected< GitRepository > initRepository(std::string const & path) const
Initialize a new git repository.
NODISCARD expected< GitRepository > initRepository(GitRepository const & repo) const
Initialize a new git repository.
NODISCARD expected< GitRepository > openRepository(std::string const & path) const
Opens an existing git repository.
NODISCARD expected< GitRepository > openRepository(GitRepository const & repo) const
Opens an existing git repository.
NODISCARD expected< GitRepository > cloneRepository(GitRepository const & repo) const
Clones a git repository.
NODISCARD expected< GitRepository > fetchRepository(GitRepository const & repo) const
Fetches the latest changes from remote repository.
NODISCARD expected< GitRepository > readRepositoryTags(GitRepository const & repo) const
Reads all tags from the repository.
NODISCARD expected< GitRepository > readRepositoryTagsMatching(GitRepository const & repo, std::string const & pattern) const
Reads tags from the repository, matching given pattern.
NODISCARD expected< void > addFile(GitRepository const & repo, std::string const & path) const
Adds a file to the repository.
NODISCARD expected< void > createInitialCommit(GitRepository const & repo, std::string const & message) const
Creates initial (empty) commit.
NODISCARD expected< std::string > commitChanges(GitRepository const & repo, std::string const & message, std::string const & parentOid) const
Commit current changes.
NODISCARD expected< std::string > getLastCommitOid(GitRepository const & repo) const
Retrieves oid of last commit in HEAD of given repository.
NODISCARD expected< void > createTagForLatestCommit(GitRepository const & repo, std::string const & tag) const
Creates tag with given name for the latest commit in HEAD of given repository.
NODISCARD expected< std::string > getCommitForTag(GitRepository const & repo, std::string const & tag) const
Retrieves commit for specified tag.
NODISCARD expected< void > checkoutBySpec(GitRepository const & repo, std::string const & spec) const
Checks out specified commit, tag or branch.
NODISCARD expected< void > stashSave(GitRepository const & repo, std::string const & message) const
Saves current changes to stash.
NODISCARD expected< void > stashPop(GitRepository const & repo) const
Apply latest stashed state from the stash list and remove it from the list if successful.
NODISCARD expected< void > stashDrop(GitRepository const & repo) const
Drop latest stashed state from the stash list.
NODISCARD expected< void > resetHardToCommitOrTag(GitRepository const & repo, std::string const & commitOrTag) const
Resets repository to the specified commit or tag.
NODISCARD expected< bool > isRepositoryDirty(GitRepository const & repo) const
Checks if repository has any uncommitted changes.
NODISCARD expected< bool > isRepositoryConflict(GitRepository const & repo) const
Checks if repository has any conflicts.
NODISCARD std::string GITAPI_USER()
NODISCARD std::string GITAPI_EMAIL()
NODISCARD std::string GIT_TAG_PATTERN_ALL()
NODISCARD std::string GIT_TAG_PATTERN_SOLUTION_VERSIONS()
NODISCARD std::string GIT_TAG_PATTERN_RT_VERSIONS()

Protected Functions

Name
NODISCARD expected< git_signature * > getDefaultSignature() const
Gets default signature of given repository.
NODISCARD expected< git_index * > openIndex(GitRepository const & repo) const
Opens index of given repository.
NODISCARD expected< git_oid > getReferenceOid(GitRepository const & repo, std::string const & name) const
Retrieves OID of reference specified by name from given repository.
NODISCARD expected< git_oid > getOidFromString(std::string const & hexString) const
Retrieves OID specified by OID hex string.
NODISCARD expected< std::string > getStringFromOid(git_oid const & oid) const
Retrieves OID hex string of given OID
NODISCARD expected< git_commit * > getCommit(GitRepository const & repo, std::string const & hexString) const
Retrieves commit specified by OID hex string from given repository.
NODISCARD expected< git_commit * > getCommit(GitRepository const & repo, git_oid const & oid) const
Retrieves commit specified by OID from given repository.
NODISCARD expected< git_commit * > getCommitByTag(GitRepository const & repo, std::string const & name) const
Retrieves git commit specified by name from given repository.
NODISCARD expected< git_oid const * > getOidFromCommit(git_commit const * commit) const
Retrieves git commit specified by name from given repository.

Detailed Description

class cvedia::rt::GitAPI;

Thin wrapper around libgit2

Public Functions Documentation

function GitAPI

GitAPI()

function ~GitAPI

~GitAPI()

function GitAPI

GitAPI(
    GitAPI const & 
) =delete

function operator=

GitAPI & operator=(
    GitAPI const & 
) =delete

function GitAPI

GitAPI(
    GitAPI && 
) =delete

function operator=

GitAPI & operator=(
    GitAPI && 
) =delete

function initRepository

NODISCARD expected< GitRepository > initRepository(
    std::string const & path
) const

Initialize a new git repository.

Parameters:

  • path Path to the repository. The directory must exist.

Return: valid GitRepository structure if successful, error if not

Note: this function does not create any directories.

function initRepository

NODISCARD expected< GitRepository > initRepository(
    GitRepository const & repo
) const

Initialize a new git repository.

Parameters:

  • repo GitRepository structure with path_ pointing to valid git repository

Return: valid GitRepository structure if successful, error if not

Note: this function does not create any directories.

function openRepository

NODISCARD expected< GitRepository > openRepository(
    std::string const & path
) const

Opens an existing git repository.

Parameters:

  • path Path to the repository. The directory must exist.

Return: valid GitRepository structure if successful, error if not

function openRepository

NODISCARD expected< GitRepository > openRepository(
    GitRepository const & repo
) const

Opens an existing git repository.

Parameters:

  • repo GitRepository structure with path_ pointing to valid git repository

Return: valid GitRepository structure if successful, error if not

function cloneRepository

NODISCARD expected< GitRepository > cloneRepository(
    GitRepository const & repo
) const

Clones a git repository.

Parameters:

  • repo GitRepository structure with path_ and uri_ fields correctly populated

Return: valid GitRepository structure if successful, error if not

function fetchRepository

NODISCARD expected< GitRepository > fetchRepository(
    GitRepository const & repo
) const

Fetches the latest changes from remote repository.

Parameters:

Return: valid GitRepository structure if successful, error if not

function readRepositoryTags

NODISCARD expected< GitRepository > readRepositoryTags(
    GitRepository const & repo
) const

Reads all tags from the repository.

Parameters:

Return: valid GitRepository structure if successful, error if not

function readRepositoryTagsMatching

NODISCARD expected< GitRepository > readRepositoryTagsMatching(
    GitRepository const & repo,
    std::string const & pattern
) const

Reads tags from the repository, matching given pattern.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • pattern Pattern to match tags against

Return: valid GitRepository structure if successful, error if not

function addFile

NODISCARD expected< void > addFile(
    GitRepository const & repo,
    std::string const & path
) const

Adds a file to the repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • path Path to the file to add

Return: error if unsuccessful

function createInitialCommit

NODISCARD expected< void > createInitialCommit(
    GitRepository const & repo,
    std::string const & message
) const

Creates initial (empty) commit.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • message Commit message

Return: error if unsuccessful

function commitChanges

NODISCARD expected< std::string > commitChanges(
    GitRepository const & repo,
    std::string const & message,
    std::string const & parentOid
) const

Commit current changes.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • message Commit message
  • parentOid OID of the parent commit

Return: valid OID if successful, error if not

function getLastCommitOid

NODISCARD expected< std::string > getLastCommitOid(
    GitRepository const & repo
) const

Retrieves oid of last commit in HEAD of given repository.

Parameters:

Return: valid OID if successful, error if not

function createTagForLatestCommit

NODISCARD expected< void > createTagForLatestCommit(
    GitRepository const & repo,
    std::string const & tag
) const

Creates tag with given name for the latest commit in HEAD of given repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • tag Name of the tag to create

Return: error if unsuccessful

function getCommitForTag

NODISCARD expected< std::string > getCommitForTag(
    GitRepository const & repo,
    std::string const & tag
) const

Retrieves commit for specified tag.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • tag Name of the tag

Return: valid 40-byte OID hex string of the commit or error if unsuccessful

function checkoutBySpec

NODISCARD expected< void > checkoutBySpec(
    GitRepository const & repo,
    std::string const & spec
) const

Checks out specified commit, tag or branch.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • spec a textual specification of an object

Return: error if unsuccessful

function stashSave

NODISCARD expected< void > stashSave(
    GitRepository const & repo,
    std::string const & message
) const

Saves current changes to stash.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • message Optional message to add to the stashed state

Return: error if unsuccessful

function stashPop

NODISCARD expected< void > stashPop(
    GitRepository const & repo
) const

Apply latest stashed state from the stash list and remove it from the list if successful.

Parameters:

Return: error if unsuccessful

function stashDrop

NODISCARD expected< void > stashDrop(
    GitRepository const & repo
) const

Drop latest stashed state from the stash list.

Parameters:

Return: error if unsuccessful

function resetHardToCommitOrTag

NODISCARD expected< void > resetHardToCommitOrTag(
    GitRepository const & repo,
    std::string const & commitOrTag
) const

Resets repository to the specified commit or tag.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • commitOrTag commit or tag to reset to

Return: valid GitRepository structure if successful, error if not

Equivalent to git reset --hard <commitOrTag>

function isRepositoryDirty

NODISCARD expected< bool > isRepositoryDirty(
    GitRepository const & repo
) const

Checks if repository has any uncommitted changes.

Parameters:

Return: true if repository has uncommitted changes, false otherwise

function isRepositoryConflict

NODISCARD expected< bool > isRepositoryConflict(
    GitRepository const & repo
) const

Checks if repository has any conflicts.

Parameters:

Return: true if repository has conflicts, false otherwise

function GITAPI_USER

static NODISCARD std::string GITAPI_USER()

function GITAPI_EMAIL

static NODISCARD std::string GITAPI_EMAIL()

function GIT_TAG_PATTERN_ALL

static NODISCARD std::string GIT_TAG_PATTERN_ALL()

function GIT_TAG_PATTERN_SOLUTION_VERSIONS

static NODISCARD std::string GIT_TAG_PATTERN_SOLUTION_VERSIONS()

function GIT_TAG_PATTERN_RT_VERSIONS

static NODISCARD std::string GIT_TAG_PATTERN_RT_VERSIONS()

Protected Functions Documentation

function getDefaultSignature

NODISCARD expected< git_signature * > getDefaultSignature() const

Gets default signature of given repository.

Return: valid git_signature pointer if successful, error if not

function openIndex

NODISCARD expected< git_index * > openIndex(
    GitRepository const & repo
) const

Opens index of given repository.

Parameters:

Return: valid git_index pointer if successful, error if not

function getReferenceOid

NODISCARD expected< git_oid > getReferenceOid(
    GitRepository const & repo,
    std::string const & name
) const

Retrieves OID of reference specified by name from given repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • name Name of the reference

Return: valid git_oid if successful, error if not

function getOidFromString

NODISCARD expected< git_oid > getOidFromString(
    std::string const & hexString
) const

Retrieves OID specified by OID hex string.

Parameters:

  • hexString valid 40-byte OID hex string

Return: valid git_oid if successful, error if not

function getStringFromOid

NODISCARD expected< std::string > getStringFromOid(
    git_oid const & oid
) const

Retrieves OID hex string of given OID

Parameters:

  • oid valid OID from repo

Return: std::string containing 40-byte OID hex string, error if not

function getCommit

NODISCARD expected< git_commit * > getCommit(
    GitRepository const & repo,
    std::string const & hexString
) const

Retrieves commit specified by OID hex string from given repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • hexString valid 40-byte OID hex string of the commit

Return: valid git_commit pointer if successful, error if not

function getCommit

NODISCARD expected< git_commit * > getCommit(
    GitRepository const & repo,
    git_oid const & oid
) const

Retrieves commit specified by OID from given repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • oid OID of the commit

Return: valid git_commit pointer if successful, error if not

function getCommitByTag

NODISCARD expected< git_commit * > getCommitByTag(
    GitRepository const & repo,
    std::string const & name
) const

Retrieves git commit specified by name from given repository.

Parameters:

  • repo GitRepository structure with valid repository_ pointer
  • name name of the tag

Return: valid git_commit pointer if successful, error if not

function getOidFromCommit

NODISCARD expected< git_oid const * > getOidFromCommit(
    git_commit const * commit
) const

Retrieves git commit specified by name from given repository.

Parameters:

  • commit valid git_commit pointer to a existing commit

Return: git_oid of the commit if successful, error if not