FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add branch info and flag to status subcommand by SandrineP · Pull Request #11 · QuantStack/git2cpp · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .build  (1) .cpp  (2) .hpp  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 15 additions & 0 deletions src/subcommand/status_subcommand.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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(); });
};
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/status_subcommand.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions src/wrapper/meson.build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
wrapper_files = files([
'refs_wrapper.cpp',
'repository_wrapper.cpp',
'status_wrapper.cpp',
])
16 changes: 16 additions & 0 deletions src/wrapper/refs_wrapper.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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);
}
23 changes: 23 additions & 0 deletions src/wrapper/refs_wrapper.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

// #include <string>

#include <git2.h>

#include "../wrapper/repository_wrapper.hpp"

class reference_wrapper : public wrapper_base<git_reference>
{
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;
};

Back | FazBrowse Home | New Git URL