#include "../subcommand/commit_subcommand.hpp"
#include
#include
#include "../utils/input_output.hpp"
#include "../wrapper/index_wrapper.hpp"
#include "../wrapper/repository_wrapper.hpp"
commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
{
auto* sub = app.add_subcommand("commit", "Record changes to the repository");
sub->add_option("-m,--message", m_commit_message, "Commit message");
sub->callback(
[this]()
{
this->run();
}
);
};
void commit_subcommand::run()
{
auto directory = get_current_git_path();
auto repo = repository_wrapper::open(directory);
auto author_committer_signatures = signature_wrapper::get_default_signature_from_env(repo);
if (m_commit_message.empty())
{
m_commit_message = prompt_input("Please enter a commit message:\n");
if (m_commit_message.empty())
{
throw std::runtime_error("Aborting, no commit message specified.");
}
}
repo.create_commit(author_committer_signatures, m_commit_message, std::nullopt);
}