commit: introduce git_commit_create_from_stage

Provide a simple helper method that allows users to create a commit from
the current index with minimal information.
This commit is contained in:
Edward Thomson
2024-01-15 00:08:16 +00:00
parent fddfca3526
commit 67a4d04b59
4 changed files with 217 additions and 1 deletions

View File

@@ -394,6 +394,36 @@ GIT_EXTERN(int) git_commit_create_v(
size_t parent_count,
...);
typedef struct {
unsigned int version;
unsigned int allow_empty_commit : 1;
const git_signature *author;
const git_signature *committer;
} git_commit_create_options;
#define GIT_COMMIT_CREATE_OPTIONS_VERSION 1
#define GIT_COMMIT_CREATE_OPTIONS_INIT { GIT_COMMIT_CREATE_OPTIONS_VERSION }
/**
* Commits the staged changes in the repository; this is a near analog to
* `git commit -m message`.
*
* By default, empty commits are not allowed.
*
* @param id pointer to store the new commit's object id
* @param repo repository to commit changes in
* @param message the commit message
* @param opts options for creating the commit
* @return 0 on success, GIT_EUNCHANGED if there were no changes to commit, or an error code
*/
GIT_EXTERN(int) git_commit_create_from_stage(
git_oid *id,
git_repository *repo,
const char *message,
const git_commit_create_options *opts);
/**
* Amend an existing commit by replacing only non-NULL values.
*