-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrevparse_subcommand.cpp
More file actions
33 lines (28 loc) · 993 Bytes
/
revparse_subcommand.cpp
File metadata and controls
33 lines (28 loc) · 993 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
#include "revparse_subcommand.hpp"
#include "../wrapper/repository_wrapper.hpp"
#include <ios>
#include <stdexcept>
revparse_subcommand::revparse_subcommand(const libgit2_object&, CLI::App& app)
{
auto* sub = app.add_subcommand("rev-parse", "Pick out and message parameters");
sub->add_flag("--is-bare-repository", m_is_bare_repository_flag);
sub->add_flag("--is-shallow-repository", m_is_shallow_repository_flag);
sub->callback([this]() { this->run(); });
}
void revparse_subcommand::run()
{
auto directory = get_current_git_path();
auto repo = repository_wrapper::open(directory);
if (m_is_bare_repository_flag)
{
std::cout << std::boolalpha << repo.is_bare() << std::endl;
}
else if (m_is_shallow_repository_flag)
{
std::cout << std::boolalpha << repo.is_shallow() << std::endl;
}
else
{
std::cout << "revparse only supports --is-bare-repository and --is-shallow-repository for now" << std::endl;
}
}