diff --git a/src/subcommand/status_subcommand.cpp b/src/subcommand/status_subcommand.cpp index 5689d13..f935884 100644 --- a/src/subcommand/status_subcommand.cpp +++ b/src/subcommand/status_subcommand.cpp @@ -6,6 +6,8 @@ #include "status_subcommand.hpp" #include "../wrapper/status_wrapper.hpp" +#include "../wrapper/refs_wrapper.hpp" + status_subcommand::status_subcommand(const libgit2_object&, CLI::App& app) { @@ -22,6 +24,7 @@ status_subcommand::status_subcommand(const libgit2_object&, CLI::App& app) // This is similar to the short output, but will remain stable across Git versions and regardless of user configuration. // See below for details. The version parameter is used to specify the format version. This is optional and defaults // to the original version v1 format."); + sub->add_flag("-b,--branch", branch_flag, "Show the branch and tracking info even in short-format."); sub->callback([this]() { this->run(); }); }; @@ -122,6 +125,7 @@ void status_subcommand::run() auto bare = false; auto repo = repository_wrapper::init(directory, bare); auto sl = status_list_wrapper::status_list(repo); + auto branch_name = reference_wrapper::get_ref_name(repo); // TODO: add branch info @@ -141,6 +145,17 @@ void status_subcommand::run() bool is_long; is_long = ((of == output_format::DEFAULT) || (of == output_format::LONG)); + if (is_long) + { + std::cout << "On branch " << branch_name << std::endl; + } + else + { + if (branch_flag) + { + std::cout << "## " << branch_name << std::endl; + } + } if (sl.has_tobecommited_header()) { if (is_long) diff --git a/src/subcommand/status_subcommand.hpp b/src/subcommand/status_subcommand.hpp index 0f2b63f..08b2893 100644 --- a/src/subcommand/status_subcommand.hpp +++ b/src/subcommand/status_subcommand.hpp @@ -12,6 +12,7 @@ class status_subcommand void run(); private: - bool short_flag = false; + bool branch_flag = false; bool long_flag = false; + bool short_flag = false; }; diff --git a/src/wrapper/meson.build b/src/wrapper/meson.build index 7f5e414..95843ff 100644 --- a/src/wrapper/meson.build +++ b/src/wrapper/meson.build @@ -1,4 +1,5 @@ wrapper_files = files([ + 'refs_wrapper.cpp', 'repository_wrapper.cpp', 'status_wrapper.cpp', ]) diff --git a/src/wrapper/refs_wrapper.cpp b/src/wrapper/refs_wrapper.cpp new file mode 100644 index 0000000..7a11c15 --- /dev/null +++ b/src/wrapper/refs_wrapper.cpp @@ -0,0 +1,16 @@ +#include "../utils/git_exception.hpp" +#include "../wrapper/refs_wrapper.hpp" + + +reference_wrapper::~reference_wrapper() +{ + git_reference_free(p_resource); + p_resource=nullptr; +} + +std::string reference_wrapper::get_ref_name(const repository_wrapper& rw) +{ + reference_wrapper ref; + throwIfError(git_repository_head(&(ref.p_resource), rw)); + return git_reference_shorthand(ref.p_resource); +} diff --git a/src/wrapper/refs_wrapper.hpp b/src/wrapper/refs_wrapper.hpp new file mode 100644 index 0000000..056e19d --- /dev/null +++ b/src/wrapper/refs_wrapper.hpp @@ -0,0 +1,23 @@ +#pragma once + +// #include + +#include + +#include "../wrapper/repository_wrapper.hpp" + +class reference_wrapper : public wrapper_base +{ +public: + + ~reference_wrapper(); + + reference_wrapper(reference_wrapper&&) = default; + reference_wrapper& operator=(reference_wrapper&&) = default; + + static std::string get_ref_name(const repository_wrapper& repo); + +private: + + reference_wrapper() = default; +};