39 const wxString& aMessage,
40 const wxString& aAuthorName,
41 const wxString& aAuthorEmail )
43 git_repository* repo =
GetRepo();
48 git_index* index =
nullptr;
50 if( git_repository_index( &index, repo ) != 0 )
52 AddErrorString( wxString::Format(
_(
"Failed to get repository index: %s" ),
59 for(
const wxString& file : aFiles )
61 if( git_index_add_bypath( index, file.mb_str() ) != 0 )
63 AddErrorString( wxString::Format(
_(
"Failed to add file to index: %s" ),
69 if( git_index_write( index ) != 0 )
78 if( git_index_write_tree( &tree_id, index ) != 0 )
85 git_tree* tree =
nullptr;
87 if( git_tree_lookup( &tree, repo, &tree_id ) != 0 )
95 git_commit* parent =
nullptr;
97 if( git_repository_head_unborn( repo ) == 0 )
99 git_reference* headRef =
nullptr;
101 if( git_repository_head( &headRef, repo ) != 0 )
103 AddErrorString( wxString::Format(
_(
"Failed to get HEAD reference: %s" ),
110 if( git_reference_peel( (git_object**) &parent, headRef, GIT_OBJECT_COMMIT ) != 0 )
120 git_signature* author =
nullptr;
122 if( git_signature_now( &author, aAuthorName.mb_str(), aAuthorEmail.mb_str() ) != 0 )
124 AddErrorString( wxString::Format(
_(
"Failed to create author signature: %s" ),
131 size_t parentsCount = parent ? 1 : 0;
132#if( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 \
133 && ( LIBGIT2_VER_REVISION < 2 || LIBGIT2_VER_REVISION == 3 ) )
134 git_commit*
const parents[1] = { parent };
135 git_commit**
const parentsPtr = parent ? parents :
nullptr;
137 const git_commit* parents[1] = { parent };
138 const git_commit** parentsPtr = parent ? parents :
nullptr;
143 if( git_commit_create( &oid, repo,
"HEAD", author, author,
nullptr,
144 aMessage.mb_str(), tree, parentsCount, parentsPtr ) != 0 )
CommitResult PerformCommit(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
virtual ~GIT_COMMIT_HANDLER()
void AddErrorString(const wxString &aErrorString)
wxString GetErrorString() const
GIT_COMMIT_HANDLER(git_repository *aRepo)
static wxString GetLastGitError()
git_repository * GetRepo() const
std::unique_ptr< git_commit, decltype([](git_commit *aCommit) { git_commit_free(aCommit) GitCommitPtr
A unique pointer for git_commit objects with automatic cleanup.
std::unique_ptr< git_tree, decltype([](git_tree *aTree) { git_tree_free(aTree) GitTreePtr
A unique pointer for git_tree objects with automatic cleanup.
std::unique_ptr< git_index, decltype([](git_index *aIndex) { git_index_free(aIndex) GitIndexPtr
A unique pointer for git_index objects with automatic cleanup.
std::unique_ptr< git_signature, decltype([](git_signature *aSignature) { git_signature_free(aSignature) GitSignaturePtr
A unique pointer for git_signature objects with automatic cleanup.
std::unique_ptr< git_reference, decltype([](git_reference *aRef) { git_reference_free(aRef) GitReferencePtr
A unique pointer for git_reference objects with automatic cleanup.