From aac0ece1ae5b8d1ee2b63f530d3321e0f7deaab1 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Sat, 19 Jul 2025 18:41:15 +0200 Subject: [PATCH 1/5] Minimal command for branches --- CMakeLists.txt | 4 ++ src/main.cpp | 2 + src/subcommand/branch_subcommand.cpp | 60 ++++++++++++++++++++++++++++ src/subcommand/branch_subcommand.hpp | 28 +++++++++++++ src/wrapper/branch_wrapper.cpp | 56 ++++++++++++++++++++++++++ src/wrapper/branch_wrapper.hpp | 56 ++++++++++++++++++++++++++ src/wrapper/commit_wrapper.cpp | 5 ++- src/wrapper/commit_wrapper.hpp | 5 ++- src/wrapper/repository_wrapper.cpp | 28 ++++++++++++- src/wrapper/repository_wrapper.hpp | 10 +++++ src/wrapper/wrapper_base.hpp | 6 ++- test/test_branch.py | 28 +++++++++++++ 12 files changed, 282 insertions(+), 6 deletions(-) create mode 100644 src/subcommand/branch_subcommand.cpp create mode 100644 src/subcommand/branch_subcommand.hpp create mode 100644 src/wrapper/branch_wrapper.cpp create mode 100644 src/wrapper/branch_wrapper.hpp create mode 100644 test/test_branch.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a5a8e5..49f3295 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ find_package(libgit2) set(GIT2CPP_SRC ${GIT2CPP_SOURCE_DIR}/subcommand/add_subcommand.cpp ${GIT2CPP_SOURCE_DIR}/subcommand/add_subcommand.hpp + ${GIT2CPP_SOURCE_DIR}/subcommand/branch_subcommand.cpp + ${GIT2CPP_SOURCE_DIR}/subcommand/branch_subcommand.hpp ${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.cpp ${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.hpp ${GIT2CPP_SOURCE_DIR}/subcommand/status_subcommand.cpp @@ -49,6 +51,8 @@ set(GIT2CPP_SRC ${GIT2CPP_SOURCE_DIR}/utils/common.hpp ${GIT2CPP_SOURCE_DIR}/utils/git_exception.cpp ${GIT2CPP_SOURCE_DIR}/utils/git_exception.hpp + ${GIT2CPP_SOURCE_DIR}/wrapper/branch_wrapper.cpp + ${GIT2CPP_SOURCE_DIR}/wrapper/branch_wrapper.hpp ${GIT2CPP_SOURCE_DIR}/wrapper/commit_wrapper.cpp ${GIT2CPP_SOURCE_DIR}/wrapper/commit_wrapper.hpp ${GIT2CPP_SOURCE_DIR}/wrapper/index_wrapper.cpp diff --git a/src/main.cpp b/src/main.cpp index 64d2b72..a04444a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "utils/git_exception.hpp" #include "version.hpp" #include "subcommand/add_subcommand.hpp" +#include "subcommand/branch_subcommand.hpp" #include "subcommand/init_subcommand.hpp" #include "subcommand/status_subcommand.hpp" @@ -23,6 +24,7 @@ int main(int argc, char** argv) init_subcommand init(lg2_obj, app); status_subcommand status(lg2_obj, app); add_subcommand add(lg2_obj, app); + branch_subcommand(lg2_obj, app); app.parse(argc, argv); diff --git a/src/subcommand/branch_subcommand.cpp b/src/subcommand/branch_subcommand.cpp new file mode 100644 index 0000000..03663a4 --- /dev/null +++ b/src/subcommand/branch_subcommand.cpp @@ -0,0 +1,60 @@ +#include + +#include "../subcommand/branch_subcommand.hpp" +#include "../wrapper/repository_wrapper.hpp" + +branch_subcommand::branch_subcommand(const libgit2_object&, CLI::App& app) +{ + auto* sub = app.add_subcommand("branch", "List, create or delete branches"); + + sub->add_option("", m_branch_name, "The name of the branch to create or delete"); + + sub->add_flag("-d,--delete", m_deletion_flag, "Delete a branch"); + sub->add_flag("-a,--all", m_all_flag, "List both remote-tracking branches and local branches"); + sub->add_flag("-r,--remotes", m_remote_flag, "List or delete (if used with -d) the remote-tracking branches"); + sub->add_flag("-l,--list", m_list_flag, "List branches"); + sub->add_flag("-f,--force", m_force_flag, "Skips confirmation"); + + sub->callback([this]() { this->run(); }); +} + +void branch_subcommand::run() +{ + auto directory = get_current_git_path(); + auto bare = false; + auto repo = repository_wrapper::open(directory); + + if (m_list_flag || m_branch_name.empty()) + { + git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL); + auto iter = repo.iterate_branches(type); + auto br = iter.next(); + while (br) + { + std::cout << br->name() << std::endl; + br = iter.next(); + } + } + else if (m_deletion_flag) + { + run_deletion(repo); + } + else + { + run_creation(repo); + } +} + +void branch_subcommand::run_deletion(repository_wrapper& repo) +{ + auto branch = repo.find_branch(m_branch_name); + // TODO: handle unmerged stated once we handle upstream repos + delete_branch(std::move(branch)); +} + + +void branch_subcommand::run_creation(repository_wrapper& repo) +{ + // TODO: handle specification of starting commit + repo.create_branch(m_branch_name, m_force_flag); +} diff --git a/src/subcommand/branch_subcommand.hpp b/src/subcommand/branch_subcommand.hpp new file mode 100644 index 0000000..8ec4203 --- /dev/null +++ b/src/subcommand/branch_subcommand.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include + +#include "../utils/common.hpp" +#include "../wrapper/repository_wrapper.hpp" + +class branch_subcommand +{ +public: + + explicit branch_subcommand(const libgit2_object&, CLI::App& app); + void run(); + +private: + + void run_deletion(repository_wrapper& repo); + void run_creation(repository_wrapper& repo); + + std::string m_branch_name = {}; + bool m_deletion_flag = false; + bool m_all_flag = false; + bool m_remote_flag = false; + bool m_list_flag = false; + bool m_force_flag = false; +}; diff --git a/src/wrapper/branch_wrapper.cpp b/src/wrapper/branch_wrapper.cpp new file mode 100644 index 0000000..86b2949 --- /dev/null +++ b/src/wrapper/branch_wrapper.cpp @@ -0,0 +1,56 @@ +#include "../utils/git_exception.hpp" +#include "../wrapper/branch_wrapper.hpp" +#include "../wrapper/commit_wrapper.hpp" +#include "../wrapper/repository_wrapper.hpp" + +#include + +branch_wrapper::branch_wrapper(git_reference* polna_ref) + : base_type(polna_ref) +{ +} + +branch_wrapper::~branch_wrapper() +{ + git_reference_free(p_resource); + p_resource=nullptr; +} + +std::string_view branch_wrapper::name() const +{ + const char* out = nullptr; + throwIfError(git_branch_name(&out, p_resource)); + return std::string_view(out); +} + +void delete_branch(branch_wrapper&& branch) +{ + throwIfError(git_branch_delete(branch)); +} + +branch_iterator::branch_iterator(git_branch_iterator* iter) + : base_type(iter) +{ +} + +branch_iterator::~branch_iterator() +{ + git_branch_iterator_free(p_resource); + p_resource = nullptr; +} + + +std::optional branch_iterator::next() +{ + git_reference* ref = nullptr; + git_branch_t type; + int res = git_branch_next(&ref, &type, p_resource); + if (res == 0) + { + return branch_wrapper(ref); + } + else + { + return std::nullopt; + } +} diff --git a/src/wrapper/branch_wrapper.hpp b/src/wrapper/branch_wrapper.hpp new file mode 100644 index 0000000..436c9e4 --- /dev/null +++ b/src/wrapper/branch_wrapper.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +#include + +#include "../wrapper/wrapper_base.hpp" + +class commit_wrapper; + +class branch_wrapper : public wrapper_base +{ +public: + + using base_type = wrapper_base; + + ~branch_wrapper(); + + branch_wrapper(branch_wrapper&&) = default; + branch_wrapper& operator=(branch_wrapper&&) = default; + + std::string_view name() const; + +private: + + explicit branch_wrapper(git_reference* ref); + + friend class repository_wrapper; + friend class branch_iterator; +}; + +void delete_branch(branch_wrapper&& br); + +// Rust / Python-like iterator instead of regular C++ iterator, +// because of the libgit2 API. Implementing the postfix increment +// operator of an input iterator would be overcomplicated. +class branch_iterator : public wrapper_base +{ +public: + + using base_type = wrapper_base; + + ~branch_iterator(); + + branch_iterator(branch_iterator&&) = default; + branch_iterator& operator=(branch_iterator&&) = default; + + std::optional next(); + +private: + + explicit branch_iterator(git_branch_iterator* iter); + + friend class repository_wrapper; +}; diff --git a/src/wrapper/commit_wrapper.cpp b/src/wrapper/commit_wrapper.cpp index b562ec5..e8168e0 100644 --- a/src/wrapper/commit_wrapper.cpp +++ b/src/wrapper/commit_wrapper.cpp @@ -1,5 +1,6 @@ -#include "commit_wrapper.hpp" #include "../utils/git_exception.hpp" +#include "../wrapper/commit_wrapper.hpp" +#include "../wrapper/repository_wrapper.hpp" commit_wrapper::~commit_wrapper() { @@ -8,7 +9,7 @@ commit_wrapper::~commit_wrapper() } -commit_wrapper commit_wrapper::last_commit(const repository_wrapper& repo, const std::string& ref_name) +commit_wrapper commit_wrapper::from_reference_name(const repository_wrapper& repo, const std::string& ref_name) { git_oid oid_parent_commit; throwIfError(git_reference_name_to_id(&oid_parent_commit, repo, ref_name.c_str())); diff --git a/src/wrapper/commit_wrapper.hpp b/src/wrapper/commit_wrapper.hpp index 4fccc47..379bd44 100644 --- a/src/wrapper/commit_wrapper.hpp +++ b/src/wrapper/commit_wrapper.hpp @@ -4,9 +4,10 @@ #include -#include "../wrapper/repository_wrapper.hpp" #include "../wrapper/wrapper_base.hpp" +class repository_wrapper; + class commit_wrapper : public wrapper_base { public: @@ -17,7 +18,7 @@ class commit_wrapper : public wrapper_base commit_wrapper& operator=(commit_wrapper&&) noexcept = default; static commit_wrapper - last_commit(const repository_wrapper& repo, const std::string& ref_name = "HEAD"); + from_reference_name(const repository_wrapper& repo, const std::string& ref_name = "HEAD"); private: diff --git a/src/wrapper/repository_wrapper.cpp b/src/wrapper/repository_wrapper.cpp index 10dc0be..750bef8 100644 --- a/src/wrapper/repository_wrapper.cpp +++ b/src/wrapper/repository_wrapper.cpp @@ -1,5 +1,5 @@ -#include "repository_wrapper.hpp" #include "../utils/git_exception.hpp" +#include "../wrapper/repository_wrapper.hpp" repository_wrapper::~repository_wrapper() { @@ -26,3 +26,29 @@ index_wrapper repository_wrapper::make_index() index_wrapper index = index_wrapper::init(*this); return index; } + +branch_wrapper repository_wrapper::create_branch(const std::string& name, bool force) +{ + return create_branch(name, commit_wrapper::from_reference_name(*this), force); +} + +branch_wrapper repository_wrapper::create_branch(const std::string& name, const commit_wrapper& commit, bool force) +{ + git_reference* branch = nullptr; + throwIfError(git_branch_create(&branch, *this, name.c_str(), commit, force)); + return branch_wrapper(branch); +} + +branch_wrapper repository_wrapper::find_branch(const std::string& name) +{ + git_reference* branch = nullptr; + throwIfError(git_branch_lookup(&branch, *this, name.c_str(), GIT_BRANCH_LOCAL)); + return branch_wrapper(branch); +} + +branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const +{ + git_branch_iterator* iter = nullptr; + git_branch_iterator_new(&iter, *this, type); + return branch_iterator(iter); +} diff --git a/src/wrapper/repository_wrapper.hpp b/src/wrapper/repository_wrapper.hpp index 16d9dfa..b060ffa 100644 --- a/src/wrapper/repository_wrapper.hpp +++ b/src/wrapper/repository_wrapper.hpp @@ -4,6 +4,8 @@ #include +#include "../wrapper/branch_wrapper.hpp" +#include "../wrapper/commit_wrapper.hpp" #include "../wrapper/index_wrapper.hpp" #include "../wrapper/wrapper_base.hpp" @@ -18,8 +20,16 @@ class repository_wrapper : public wrapper_base static repository_wrapper init(const std::string& directory, bool bare); static repository_wrapper open(const std::string& directory); + index_wrapper make_index(); + branch_wrapper create_branch(const std::string& name, bool force); + branch_wrapper create_branch(const std::string& name, const commit_wrapper& commit, bool force); + + branch_wrapper find_branch(const std::string& name); + + branch_iterator iterate_branches(git_branch_t type) const; + private: repository_wrapper() = default; diff --git a/src/wrapper/wrapper_base.hpp b/src/wrapper/wrapper_base.hpp index 4750f64..424f274 100644 --- a/src/wrapper/wrapper_base.hpp +++ b/src/wrapper/wrapper_base.hpp @@ -28,7 +28,11 @@ class wrapper_base protected: // Allocation and deletion of p_resource must be handled by inheriting class. - wrapper_base() = default; + explicit wrapper_base(resource_type* resource = nullptr) + : p_resource(resource) + { + } + ~wrapper_base() = default; resource_type* p_resource = nullptr; diff --git a/test/test_branch.py b/test/test_branch.py new file mode 100644 index 0000000..b87815c --- /dev/null +++ b/test/test_branch.py @@ -0,0 +1,28 @@ +import os +import subprocess + +import pytest + +@pytest.fixture +def rename_git(): + os.rename("test/data/status_data/embeded_git/", "test/data/status_data/.git/") + yield + os.rename("test/data/status_data/.git/", "test/data/status_data/embeded_git/") + +def test_branch_list(rename_git, git2cpp_path): + cmd = [git2cpp_path, 'branch'] + p = subprocess.run(cmd, capture_output=True, cwd="test/data/status_data", text=True) + assert('main' in p.stdout == 'main\n') + +def test_branch_create_delete(rename_git, git2cpp_path): + create_cmd = [git2cpp_path, 'branch', 'foregone'] + subprocess.run(create_cmd, capture_output=True, cwd="test/data/status_data", text=True) + list_cmd = [git2cpp_path, 'branch'] + p = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True) + assert(p.stdout == 'foregone\nmain\n') + del_cmd = [git2cpp_path, 'branch', '-d', 'foregone'] + subprocess.run(del_cmd, capture_output=True, cwd="test/data/status_data", text=True) + p2 = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True) + assert(p2.stdout == 'main\n') + + From 3ee5cfcf2c2dab2e33bc690b2ca66eb1a2c4a41f Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Sat, 19 Jul 2025 18:49:33 +0200 Subject: [PATCH 2/5] copilot revision --- src/wrapper/branch_wrapper.cpp | 2 +- src/wrapper/repository_wrapper.cpp | 2 +- test/test_branch.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wrapper/branch_wrapper.cpp b/src/wrapper/branch_wrapper.cpp index 86b2949..ccb334a 100644 --- a/src/wrapper/branch_wrapper.cpp +++ b/src/wrapper/branch_wrapper.cpp @@ -13,7 +13,7 @@ branch_wrapper::branch_wrapper(git_reference* polna_ref) branch_wrapper::~branch_wrapper() { git_reference_free(p_resource); - p_resource=nullptr; + p_resource = nullptr; } std::string_view branch_wrapper::name() const diff --git a/src/wrapper/repository_wrapper.cpp b/src/wrapper/repository_wrapper.cpp index 750bef8..4cb37b4 100644 --- a/src/wrapper/repository_wrapper.cpp +++ b/src/wrapper/repository_wrapper.cpp @@ -49,6 +49,6 @@ branch_wrapper repository_wrapper::find_branch(const std::string& name) branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const { git_branch_iterator* iter = nullptr; - git_branch_iterator_new(&iter, *this, type); + throwIfError(git_branch_iterator_new(&iter, *this, type)); return branch_iterator(iter); } diff --git a/test/test_branch.py b/test/test_branch.py index b87815c..f6ebcd4 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -12,7 +12,7 @@ def rename_git(): def test_branch_list(rename_git, git2cpp_path): cmd = [git2cpp_path, 'branch'] p = subprocess.run(cmd, capture_output=True, cwd="test/data/status_data", text=True) - assert('main' in p.stdout == 'main\n') + assert(p.stdout == 'main\n') def test_branch_create_delete(rename_git, git2cpp_path): create_cmd = [git2cpp_path, 'branch', 'foregone'] From e1c5ce25d550e4fb82521780f7a94cda6c139398 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Sun, 20 Jul 2025 11:33:30 +0200 Subject: [PATCH 3/5] Displays current branch when listing --- src/subcommand/branch_subcommand.cpp | 10 +++++++--- src/subcommand/status_subcommand.cpp | 2 +- src/wrapper/refs_wrapper.cpp | 10 ++++++---- src/wrapper/refs_wrapper.hpp | 9 ++++++--- src/wrapper/repository_wrapper.cpp | 7 +++++++ src/wrapper/repository_wrapper.hpp | 3 +++ test/test_branch.py | 6 +++--- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/subcommand/branch_subcommand.cpp b/src/subcommand/branch_subcommand.cpp index 03663a4..c6e297c 100644 --- a/src/subcommand/branch_subcommand.cpp +++ b/src/subcommand/branch_subcommand.cpp @@ -21,17 +21,21 @@ branch_subcommand::branch_subcommand(const libgit2_object&, CLI::App& app) void branch_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; auto repo = repository_wrapper::open(directory); if (m_list_flag || m_branch_name.empty()) { - git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL); + auto head_name = repo.head().short_name(); + std::cout << "* " << head_name << std::endl; + git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL); auto iter = repo.iterate_branches(type); auto br = iter.next(); while (br) { - std::cout << br->name() << std::endl; + if (br->name() != head_name) + { + std::cout << " " << br->name() << std::endl; + } br = iter.next(); } } diff --git a/src/subcommand/status_subcommand.cpp b/src/subcommand/status_subcommand.cpp index 2da0780..83ebd6d 100644 --- a/src/subcommand/status_subcommand.cpp +++ b/src/subcommand/status_subcommand.cpp @@ -186,7 +186,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); + auto branch_name = repo.head().short_name(); std::set tracked_dir_set{}; std::set untracked_dir_set{}; diff --git a/src/wrapper/refs_wrapper.cpp b/src/wrapper/refs_wrapper.cpp index 7a11c15..32e8881 100644 --- a/src/wrapper/refs_wrapper.cpp +++ b/src/wrapper/refs_wrapper.cpp @@ -1,6 +1,10 @@ #include "../utils/git_exception.hpp" #include "../wrapper/refs_wrapper.hpp" +reference_wrapper::reference_wrapper(git_reference* jaila_ref) + : base_type(jaila_ref) +{ +} reference_wrapper::~reference_wrapper() { @@ -8,9 +12,7 @@ reference_wrapper::~reference_wrapper() p_resource=nullptr; } -std::string reference_wrapper::get_ref_name(const repository_wrapper& rw) +std::string reference_wrapper::short_name() const { - reference_wrapper ref; - throwIfError(git_repository_head(&(ref.p_resource), rw)); - return git_reference_shorthand(ref.p_resource); + return git_reference_shorthand(p_resource); } diff --git a/src/wrapper/refs_wrapper.hpp b/src/wrapper/refs_wrapper.hpp index 32f139b..dfe32a7 100644 --- a/src/wrapper/refs_wrapper.hpp +++ b/src/wrapper/refs_wrapper.hpp @@ -4,21 +4,24 @@ #include -#include "../wrapper/repository_wrapper.hpp" #include "../wrapper/wrapper_base.hpp" class reference_wrapper : public wrapper_base { public: + using base_type = wrapper_base; + ~reference_wrapper(); reference_wrapper(reference_wrapper&&) noexcept = default; reference_wrapper& operator=(reference_wrapper&&) noexcept = default; - static std::string get_ref_name(const repository_wrapper& repo); + std::string short_name() const; private: - reference_wrapper() = default; + reference_wrapper(git_reference* ref); + + friend class repository_wrapper; }; diff --git a/src/wrapper/repository_wrapper.cpp b/src/wrapper/repository_wrapper.cpp index 4cb37b4..c35eece 100644 --- a/src/wrapper/repository_wrapper.cpp +++ b/src/wrapper/repository_wrapper.cpp @@ -21,6 +21,13 @@ repository_wrapper repository_wrapper::init(const std::string& directory, bool b return rw; } +reference_wrapper repository_wrapper::head() const +{ + git_reference* ref; + throwIfError(git_repository_head(&ref, *this)); + return reference_wrapper(ref); +} + index_wrapper repository_wrapper::make_index() { index_wrapper index = index_wrapper::init(*this); diff --git a/src/wrapper/repository_wrapper.hpp b/src/wrapper/repository_wrapper.hpp index b060ffa..cf07a20 100644 --- a/src/wrapper/repository_wrapper.hpp +++ b/src/wrapper/repository_wrapper.hpp @@ -7,6 +7,7 @@ #include "../wrapper/branch_wrapper.hpp" #include "../wrapper/commit_wrapper.hpp" #include "../wrapper/index_wrapper.hpp" +#include "../wrapper/refs_wrapper.hpp" #include "../wrapper/wrapper_base.hpp" class repository_wrapper : public wrapper_base @@ -21,6 +22,8 @@ class repository_wrapper : public wrapper_base static repository_wrapper init(const std::string& directory, bool bare); static repository_wrapper open(const std::string& directory); + reference_wrapper head() const; + index_wrapper make_index(); branch_wrapper create_branch(const std::string& name, bool force); diff --git a/test/test_branch.py b/test/test_branch.py index f6ebcd4..4c875a8 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -12,17 +12,17 @@ def rename_git(): def test_branch_list(rename_git, git2cpp_path): cmd = [git2cpp_path, 'branch'] p = subprocess.run(cmd, capture_output=True, cwd="test/data/status_data", text=True) - assert(p.stdout == 'main\n') + assert(p.stdout == '* main\n') def test_branch_create_delete(rename_git, git2cpp_path): create_cmd = [git2cpp_path, 'branch', 'foregone'] subprocess.run(create_cmd, capture_output=True, cwd="test/data/status_data", text=True) list_cmd = [git2cpp_path, 'branch'] p = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True) - assert(p.stdout == 'foregone\nmain\n') + assert(p.stdout == '* main\n foregone\n') del_cmd = [git2cpp_path, 'branch', '-d', 'foregone'] subprocess.run(del_cmd, capture_output=True, cwd="test/data/status_data", text=True) p2 = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True) - assert(p2.stdout == 'main\n') + assert(p2.stdout == '* main\n') From aab94f60c7170cf2442cb12a1dbc3d4c31fb3b5d Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Mon, 21 Jul 2025 12:31:17 +0200 Subject: [PATCH 4/5] Better arguments names --- src/wrapper/branch_wrapper.cpp | 4 ++-- src/wrapper/refs_wrapper.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wrapper/branch_wrapper.cpp b/src/wrapper/branch_wrapper.cpp index ccb334a..afc5d64 100644 --- a/src/wrapper/branch_wrapper.cpp +++ b/src/wrapper/branch_wrapper.cpp @@ -5,8 +5,8 @@ #include -branch_wrapper::branch_wrapper(git_reference* polna_ref) - : base_type(polna_ref) +branch_wrapper::branch_wrapper(git_reference* ref) + : base_type(ref) { } diff --git a/src/wrapper/refs_wrapper.cpp b/src/wrapper/refs_wrapper.cpp index 32e8881..21ef84b 100644 --- a/src/wrapper/refs_wrapper.cpp +++ b/src/wrapper/refs_wrapper.cpp @@ -1,8 +1,8 @@ #include "../utils/git_exception.hpp" #include "../wrapper/refs_wrapper.hpp" -reference_wrapper::reference_wrapper(git_reference* jaila_ref) - : base_type(jaila_ref) +reference_wrapper::reference_wrapper(git_reference* ref) + : base_type(ref) { } From 0b6cab5176a8e34cb85514f21a2f1dc8ca8f474d Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Mon, 21 Jul 2025 12:32:39 +0200 Subject: [PATCH 5/5] Fixed typo in embeded_git --- .../{embeded_git => embedded_git}/COMMIT_EDITMSG | 0 .../status_data/{embeded_git => embedded_git}/HEAD | 0 .../{embeded_git => embedded_git}/config | 0 .../{embeded_git => embedded_git}/description | 0 .../hooks/applypatch-msg.sample | 0 .../hooks/commit-msg.sample | 0 .../hooks/fsmonitor-watchman.sample | 0 .../hooks/post-update.sample | 0 .../hooks/pre-applypatch.sample | 0 .../hooks/pre-commit.sample | 0 .../hooks/pre-merge-commit.sample | 0 .../hooks/pre-push.sample | 0 .../hooks/pre-rebase.sample | 0 .../hooks/pre-receive.sample | 0 .../hooks/prepare-commit-msg.sample | 0 .../hooks/push-to-checkout.sample | 0 .../hooks/sendemail-validate.sample | 0 .../hooks/update.sample | 0 .../status_data/{embeded_git => embedded_git}/index | Bin .../{embeded_git => embedded_git}/info/exclude | 0 .../{embeded_git => embedded_git}/logs/HEAD | 0 .../logs/refs/heads/main | 0 .../75/743dcbd85064226c77a0b862af817838ae0b2e | Bin .../9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 | Bin .../bd/ef436c07ee899d19659581d2944f573ac620e0 | Bin .../dc/430e3c2e6e1193b377040126b95099261e7251 | Bin .../e3/323b422ccebe9515b4aa335b40615f398b6553 | Bin .../ee/8c4cf874c4f1e3ba755f929fe7811018adee3d | 0 .../fd/511fbb5dd2860baabf28e298fa3373634e8660 | Bin .../{embeded_git => embedded_git}/refs/heads/main | 0 test/test_branch.py | 4 ++-- test/test_status.py | 4 ++-- 32 files changed, 4 insertions(+), 4 deletions(-) rename test/data/status_data/{embeded_git => embedded_git}/COMMIT_EDITMSG (100%) rename test/data/status_data/{embeded_git => embedded_git}/HEAD (100%) rename test/data/status_data/{embeded_git => embedded_git}/config (100%) rename test/data/status_data/{embeded_git => embedded_git}/description (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/applypatch-msg.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/commit-msg.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/fsmonitor-watchman.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/post-update.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-applypatch.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-commit.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-merge-commit.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-push.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-rebase.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/pre-receive.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/prepare-commit-msg.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/push-to-checkout.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/sendemail-validate.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/hooks/update.sample (100%) rename test/data/status_data/{embeded_git => embedded_git}/index (100%) rename test/data/status_data/{embeded_git => embedded_git}/info/exclude (100%) rename test/data/status_data/{embeded_git => embedded_git}/logs/HEAD (100%) rename test/data/status_data/{embeded_git => embedded_git}/logs/refs/heads/main (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/75/743dcbd85064226c77a0b862af817838ae0b2e (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/bd/ef436c07ee899d19659581d2944f573ac620e0 (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/dc/430e3c2e6e1193b377040126b95099261e7251 (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/e3/323b422ccebe9515b4aa335b40615f398b6553 (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/ee/8c4cf874c4f1e3ba755f929fe7811018adee3d (100%) rename test/data/status_data/{embeded_git => embedded_git}/objects/fd/511fbb5dd2860baabf28e298fa3373634e8660 (100%) rename test/data/status_data/{embeded_git => embedded_git}/refs/heads/main (100%) diff --git a/test/data/status_data/embeded_git/COMMIT_EDITMSG b/test/data/status_data/embedded_git/COMMIT_EDITMSG similarity index 100% rename from test/data/status_data/embeded_git/COMMIT_EDITMSG rename to test/data/status_data/embedded_git/COMMIT_EDITMSG diff --git a/test/data/status_data/embeded_git/HEAD b/test/data/status_data/embedded_git/HEAD similarity index 100% rename from test/data/status_data/embeded_git/HEAD rename to test/data/status_data/embedded_git/HEAD diff --git a/test/data/status_data/embeded_git/config b/test/data/status_data/embedded_git/config similarity index 100% rename from test/data/status_data/embeded_git/config rename to test/data/status_data/embedded_git/config diff --git a/test/data/status_data/embeded_git/description b/test/data/status_data/embedded_git/description similarity index 100% rename from test/data/status_data/embeded_git/description rename to test/data/status_data/embedded_git/description diff --git a/test/data/status_data/embeded_git/hooks/applypatch-msg.sample b/test/data/status_data/embedded_git/hooks/applypatch-msg.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/applypatch-msg.sample rename to test/data/status_data/embedded_git/hooks/applypatch-msg.sample diff --git a/test/data/status_data/embeded_git/hooks/commit-msg.sample b/test/data/status_data/embedded_git/hooks/commit-msg.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/commit-msg.sample rename to test/data/status_data/embedded_git/hooks/commit-msg.sample diff --git a/test/data/status_data/embeded_git/hooks/fsmonitor-watchman.sample b/test/data/status_data/embedded_git/hooks/fsmonitor-watchman.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/fsmonitor-watchman.sample rename to test/data/status_data/embedded_git/hooks/fsmonitor-watchman.sample diff --git a/test/data/status_data/embeded_git/hooks/post-update.sample b/test/data/status_data/embedded_git/hooks/post-update.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/post-update.sample rename to test/data/status_data/embedded_git/hooks/post-update.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-applypatch.sample b/test/data/status_data/embedded_git/hooks/pre-applypatch.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-applypatch.sample rename to test/data/status_data/embedded_git/hooks/pre-applypatch.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-commit.sample b/test/data/status_data/embedded_git/hooks/pre-commit.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-commit.sample rename to test/data/status_data/embedded_git/hooks/pre-commit.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-merge-commit.sample b/test/data/status_data/embedded_git/hooks/pre-merge-commit.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-merge-commit.sample rename to test/data/status_data/embedded_git/hooks/pre-merge-commit.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-push.sample b/test/data/status_data/embedded_git/hooks/pre-push.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-push.sample rename to test/data/status_data/embedded_git/hooks/pre-push.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-rebase.sample b/test/data/status_data/embedded_git/hooks/pre-rebase.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-rebase.sample rename to test/data/status_data/embedded_git/hooks/pre-rebase.sample diff --git a/test/data/status_data/embeded_git/hooks/pre-receive.sample b/test/data/status_data/embedded_git/hooks/pre-receive.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/pre-receive.sample rename to test/data/status_data/embedded_git/hooks/pre-receive.sample diff --git a/test/data/status_data/embeded_git/hooks/prepare-commit-msg.sample b/test/data/status_data/embedded_git/hooks/prepare-commit-msg.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/prepare-commit-msg.sample rename to test/data/status_data/embedded_git/hooks/prepare-commit-msg.sample diff --git a/test/data/status_data/embeded_git/hooks/push-to-checkout.sample b/test/data/status_data/embedded_git/hooks/push-to-checkout.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/push-to-checkout.sample rename to test/data/status_data/embedded_git/hooks/push-to-checkout.sample diff --git a/test/data/status_data/embeded_git/hooks/sendemail-validate.sample b/test/data/status_data/embedded_git/hooks/sendemail-validate.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/sendemail-validate.sample rename to test/data/status_data/embedded_git/hooks/sendemail-validate.sample diff --git a/test/data/status_data/embeded_git/hooks/update.sample b/test/data/status_data/embedded_git/hooks/update.sample similarity index 100% rename from test/data/status_data/embeded_git/hooks/update.sample rename to test/data/status_data/embedded_git/hooks/update.sample diff --git a/test/data/status_data/embeded_git/index b/test/data/status_data/embedded_git/index similarity index 100% rename from test/data/status_data/embeded_git/index rename to test/data/status_data/embedded_git/index diff --git a/test/data/status_data/embeded_git/info/exclude b/test/data/status_data/embedded_git/info/exclude similarity index 100% rename from test/data/status_data/embeded_git/info/exclude rename to test/data/status_data/embedded_git/info/exclude diff --git a/test/data/status_data/embeded_git/logs/HEAD b/test/data/status_data/embedded_git/logs/HEAD similarity index 100% rename from test/data/status_data/embeded_git/logs/HEAD rename to test/data/status_data/embedded_git/logs/HEAD diff --git a/test/data/status_data/embeded_git/logs/refs/heads/main b/test/data/status_data/embedded_git/logs/refs/heads/main similarity index 100% rename from test/data/status_data/embeded_git/logs/refs/heads/main rename to test/data/status_data/embedded_git/logs/refs/heads/main diff --git a/test/data/status_data/embeded_git/objects/75/743dcbd85064226c77a0b862af817838ae0b2e b/test/data/status_data/embedded_git/objects/75/743dcbd85064226c77a0b862af817838ae0b2e similarity index 100% rename from test/data/status_data/embeded_git/objects/75/743dcbd85064226c77a0b862af817838ae0b2e rename to test/data/status_data/embedded_git/objects/75/743dcbd85064226c77a0b862af817838ae0b2e diff --git a/test/data/status_data/embeded_git/objects/9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 b/test/data/status_data/embedded_git/objects/9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 similarity index 100% rename from test/data/status_data/embeded_git/objects/9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 rename to test/data/status_data/embedded_git/objects/9c/a9a8716bf7f5ab1ff449be0c97a04a7aae4262 diff --git a/test/data/status_data/embeded_git/objects/bd/ef436c07ee899d19659581d2944f573ac620e0 b/test/data/status_data/embedded_git/objects/bd/ef436c07ee899d19659581d2944f573ac620e0 similarity index 100% rename from test/data/status_data/embeded_git/objects/bd/ef436c07ee899d19659581d2944f573ac620e0 rename to test/data/status_data/embedded_git/objects/bd/ef436c07ee899d19659581d2944f573ac620e0 diff --git a/test/data/status_data/embeded_git/objects/dc/430e3c2e6e1193b377040126b95099261e7251 b/test/data/status_data/embedded_git/objects/dc/430e3c2e6e1193b377040126b95099261e7251 similarity index 100% rename from test/data/status_data/embeded_git/objects/dc/430e3c2e6e1193b377040126b95099261e7251 rename to test/data/status_data/embedded_git/objects/dc/430e3c2e6e1193b377040126b95099261e7251 diff --git a/test/data/status_data/embeded_git/objects/e3/323b422ccebe9515b4aa335b40615f398b6553 b/test/data/status_data/embedded_git/objects/e3/323b422ccebe9515b4aa335b40615f398b6553 similarity index 100% rename from test/data/status_data/embeded_git/objects/e3/323b422ccebe9515b4aa335b40615f398b6553 rename to test/data/status_data/embedded_git/objects/e3/323b422ccebe9515b4aa335b40615f398b6553 diff --git a/test/data/status_data/embeded_git/objects/ee/8c4cf874c4f1e3ba755f929fe7811018adee3d b/test/data/status_data/embedded_git/objects/ee/8c4cf874c4f1e3ba755f929fe7811018adee3d similarity index 100% rename from test/data/status_data/embeded_git/objects/ee/8c4cf874c4f1e3ba755f929fe7811018adee3d rename to test/data/status_data/embedded_git/objects/ee/8c4cf874c4f1e3ba755f929fe7811018adee3d diff --git a/test/data/status_data/embeded_git/objects/fd/511fbb5dd2860baabf28e298fa3373634e8660 b/test/data/status_data/embedded_git/objects/fd/511fbb5dd2860baabf28e298fa3373634e8660 similarity index 100% rename from test/data/status_data/embeded_git/objects/fd/511fbb5dd2860baabf28e298fa3373634e8660 rename to test/data/status_data/embedded_git/objects/fd/511fbb5dd2860baabf28e298fa3373634e8660 diff --git a/test/data/status_data/embeded_git/refs/heads/main b/test/data/status_data/embedded_git/refs/heads/main similarity index 100% rename from test/data/status_data/embeded_git/refs/heads/main rename to test/data/status_data/embedded_git/refs/heads/main diff --git a/test/test_branch.py b/test/test_branch.py index 4c875a8..c6d5882 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -5,9 +5,9 @@ @pytest.fixture def rename_git(): - os.rename("test/data/status_data/embeded_git/", "test/data/status_data/.git/") + os.rename("test/data/status_data/embedded_git/", "test/data/status_data/.git/") yield - os.rename("test/data/status_data/.git/", "test/data/status_data/embeded_git/") + os.rename("test/data/status_data/.git/", "test/data/status_data/embedded_git/") def test_branch_list(rename_git, git2cpp_path): cmd = [git2cpp_path, 'branch'] diff --git a/test/test_status.py b/test/test_status.py index 87abb3d..49f8470 100644 --- a/test/test_status.py +++ b/test/test_status.py @@ -7,9 +7,9 @@ @pytest.fixture def rename_git(): - os.rename("test/data/status_data/embeded_git/", "test/data/status_data/.git/") + os.rename("test/data/status_data/embedded_git/", "test/data/status_data/.git/") yield - os.rename("test/data/status_data/.git/", "test/data/status_data/embeded_git/") + os.rename("test/data/status_data/.git/", "test/data/status_data/embedded_git/") @pytest.mark.parametrize("short_flag", ["", "-s", "--short"])