Add ```show-ref``` subcommand by SandrineP · Pull Request #142 · QuantStack/git2cpp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "subcommand/revlist_subcommand.hpp"
#include "subcommand/revparse_subcommand.hpp"
#include "subcommand/rm_subcommand.hpp"
#include "subcommand/showref_subcommand.hpp"
#include "subcommand/stash_subcommand.hpp"
#include "subcommand/status_subcommand.hpp"
#include "subcommand/tag_subcommand.hpp"
Expand Down Expand Up @@ -63,6 +64,7 @@ int main(int argc, char** argv)
rm_subcommand rm(lg2_obj, app);
stash_subcommand stash(lg2_obj, app);
tag_subcommand tag(lg2_obj, app);
showref_subcommand showref(lg2_obj, app);

app.require_subcommand(/* min */ 0, /* max */ 1);

Expand Down
31 changes: 31 additions & 0 deletions src/subcommand/showref_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "showref_subcommand.hpp"

#include <git2.h>

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

showref_subcommand::showref_subcommand(const libgit2_object&, CLI::App& app)
{
auto* sub = app.add_subcommand("show-ref", "List references in a local repository");

sub->callback(
[this]()
{
this->run();
}
);
};

void showref_subcommand::run()
{
auto directory = get_current_git_path();
auto repo = repository_wrapper::open(directory);

auto repo_refs = repo.refs_list();

for (auto r : repo_refs)
{
git_oid oid = repo.ref_name_to_id(r);
std::cout << oid_to_hex(oid) << " " << r << std::endl;
}
}
13 changes: 13 additions & 0 deletions src/subcommand/showref_subcommand.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <CLI/CLI.hpp>

#include "../utils/common.hpp"

class showref_subcommand
{
public:

explicit showref_subcommand(const libgit2_object&, CLI::App& app);
void run();
};
1 change: 1 addition & 0 deletions src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <git2.h>

#include "../utils/common.hpp"
#include "../utils/git_exception.hpp"
#include "../wrapper/annotated_commit_wrapper.hpp"
#include "../wrapper/branch_wrapper.hpp"
Expand Down
3 changes: 2 additions & 1 deletion test/test_fetch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import subprocess

import pytest


@pytest.mark.parametrize("protocol", ["http", "https"])
def test_fetch_private_repo(git2cpp_path, tmp_path, run_in_tmp_path, private_test_repo, protocol):
Expand Down
48 changes: 48 additions & 0 deletions test/test_showref.py