forked from QuantStack/git2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_subcommand.cpp
More file actions
34 lines (24 loc) · 965 Bytes
/
commit_subcommand.cpp
File metadata and controls
34 lines (24 loc) · 965 Bytes
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
#include <git2.h>
#include <unistd.h>
#include "commit_subcommand.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("commit_message", m_commit_message, "Commit message");
sub->add_flag("-m,--message", m_commit_message_flag, "");
sub->callback([this]() { this->run(); });
};
void commit_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto author_committer_signatures = signature_wrapper::get_default_signature_from_env(repo);
if (!m_commit_message_flag)
{
throw std::runtime_error("Please provide a message using the -m flag.");
}
repo.create_commit(author_committer_signatures, m_commit_message);
}