Skip to content
Prev Previous commit
Next Next commit
edit option
  • Loading branch information
SandrineP committed Jul 31, 2025
commit d6c35c3667b7e1cbd01da52af4b339f5ba4a8ad7
17 changes: 7 additions & 10 deletions src/subcommand/commit_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
{
auto *sub = app.add_subcommand("commit", "Record changes to the repository");

// TODO: merge the following option and flag into: sub->add_option("-m,--message", m_commit_message, "Commit message")
// when we have a solution to ask for a message when not using the -m flag.
sub->add_option("commit_message", m_commit_message, "Commit message");

sub->add_flag("-m,--message", m_commit_message_flag, "");
sub->add_option("-m,--message", m_commit_message, "Commit message");

sub->callback([this]() { this->run(); });
};
Expand All @@ -27,13 +23,14 @@ void commit_subcommand::run()
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.");
}
if (m_commit_message.empty())
{
throw std::runtime_error("Please provide a commit message.");
std::cout << "Please enter a commit message: " << std::endl;
std::getline(std::cin, m_commit_message);
if (m_commit_message.empty())
{
throw std::runtime_error("Aborting, no commit message specified.");
}
}

repo.create_commit(author_committer_signatures, m_commit_message);
Expand Down
1 change: 0 additions & 1 deletion src/subcommand/commit_subcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ class commit_subcommand
void run();

private:
bool m_commit_message_flag = true; // TODO: change to false when a message can be provided if the "-m" flag is not provided
std::string m_commit_message;
};
Loading