-
Notifications
You must be signed in to change notification settings - Fork 5
Add --abbrev-commit, --format=oneline and --oneline to the log subcommand
#118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,32 @@ | ||
| #include "revparse_subcommand.hpp" | ||
| #include "../utils/git_exception.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); | ||
| auto* bare_opt = sub->add_flag("--is-bare-repository", m_is_bare_repository_flag, "When the repository is bare print \"true\", otherwise \"false\"."); | ||
| auto* shallow_opt = sub->add_flag("--is-shallow-repository", m_is_shallow_repository_flag, "When the repository is shallow print \"true\", otherwise \"false\"."); | ||
| auto* rev_opt = sub->add_option("<rev>", m_revisions, "Revision(s) to parse (e.g. HEAD, main, HEAD~1, dae86e, ...)"); | ||
|
|
||
| sub->parse_complete_callback([this, sub, bare_opt, shallow_opt, rev_opt]() { | ||
| for (CLI::Option* opt : sub->parse_order()) | ||
| { | ||
| if (opt == bare_opt) | ||
| { | ||
| m_queries_in_order.push_back("is_bare"); | ||
| } | ||
| else if (opt == shallow_opt) | ||
| { | ||
| m_queries_in_order.push_back("is_shallow"); | ||
| } | ||
| else if (opt == rev_opt) | ||
| { | ||
| m_queries_in_order.push_back("is_rev"); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| sub->callback([this]() { this->run(); }); | ||
| } | ||
|
|
@@ -18,16 +36,34 @@ 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) | ||
| size_t i = 0; | ||
| if (!m_queries_in_order.empty()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed now as the following for-loop will do nothing if |
||
| { | ||
| 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; | ||
| for (const auto& q : m_queries_in_order) | ||
| { | ||
| if (q == "is_bare") | ||
| { | ||
| std::cout << std::boolalpha << repo.is_bare() << std::endl; | ||
| } | ||
| else if (q == "is_shallow") | ||
| { | ||
| std::cout << std::boolalpha << repo.is_shallow() << std::endl; | ||
| } | ||
| else if (q == "is_rev") | ||
| { | ||
| const auto& rev = m_revisions[i]; | ||
| auto obj = repo.revparse_single(rev.c_str()); | ||
|
|
||
| if (!obj.has_value()) | ||
| { | ||
| throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT); | ||
| } | ||
|
|
||
| auto oid = obj.value().oid(); | ||
| std::cout << git_oid_tostr_s(&oid) << std::endl; | ||
| i += 1; | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed any more. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add surrounding curly braces