-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommit_subcommand.cpp
More file actions
36 lines (27 loc) · 1.05 KB
/
commit_subcommand.cpp
File metadata and controls
36 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <git2.h>
#include <unistd.h>
#include "../subcommand/commit_subcommand.hpp"
#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);
}