From 3bc938ae63f3bf82d3ff99a8b0863784065e4443 Mon Sep 17 00:00:00 2001 From: Sandrine Pataut Date: Mon, 12 Jan 2026 17:52:48 +0100 Subject: [PATCH] Adds git config --- CMakeLists.txt | 4 ++ src/main.cpp | 2 + src/subcommand/add_subcommand.cpp | 2 +- src/subcommand/config_subcommand.cpp | 100 +++++++++++++++++++++++++++ src/subcommand/config_subcommand.hpp | 23 ++++++ src/wrapper/config_wrapper.cpp | 30 ++++++++ src/wrapper/config_wrapper.hpp | 29 ++++++++ src/wrapper/repository_wrapper.cpp | 11 +++ src/wrapper/repository_wrapper.hpp | 4 ++ test/conftest.py | 15 +++- test/test_commit.py | 18 +++-- test/test_config.py | 72 +++++++++++++++++++ test/test_log.py | 24 ++++--- test/test_merge.py | 10 ++- test/test_remote.py | 2 +- test/test_reset.py | 14 ++-- test/test_revlist.py | 2 +- 17 files changed, 330 insertions(+), 32 deletions(-) create mode 100644 src/subcommand/config_subcommand.cpp create mode 100644 src/subcommand/config_subcommand.hpp create mode 100644 src/wrapper/config_wrapper.cpp create mode 100644 src/wrapper/config_wrapper.hpp create mode 100644 test/test_config.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 36b401b..ef52831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ set(GIT2CPP_SRC ${GIT2CPP_SOURCE_DIR}/subcommand/clone_subcommand.hpp ${GIT2CPP_SOURCE_DIR}/subcommand/commit_subcommand.cpp ${GIT2CPP_SOURCE_DIR}/subcommand/commit_subcommand.hpp + ${GIT2CPP_SOURCE_DIR}/subcommand/config_subcommand.cpp + ${GIT2CPP_SOURCE_DIR}/subcommand/config_subcommand.hpp ${GIT2CPP_SOURCE_DIR}/subcommand/fetch_subcommand.cpp ${GIT2CPP_SOURCE_DIR}/subcommand/fetch_subcommand.hpp ${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.cpp @@ -88,6 +90,8 @@ set(GIT2CPP_SRC ${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/config_wrapper.cpp + ${GIT2CPP_SOURCE_DIR}/wrapper/config_wrapper.hpp ${GIT2CPP_SOURCE_DIR}/wrapper/index_wrapper.cpp ${GIT2CPP_SOURCE_DIR}/wrapper/index_wrapper.hpp ${GIT2CPP_SOURCE_DIR}/wrapper/object_wrapper.cpp diff --git a/src/main.cpp b/src/main.cpp index 9a3012b..8aa4c0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include "subcommand/checkout_subcommand.hpp" #include "subcommand/clone_subcommand.hpp" #include "subcommand/commit_subcommand.hpp" +#include "subcommand/config_subcommand.hpp" #include "subcommand/fetch_subcommand.hpp" #include "subcommand/init_subcommand.hpp" #include "subcommand/log_subcommand.hpp" @@ -40,6 +41,7 @@ int main(int argc, char** argv) checkout_subcommand checkout(lg2_obj, app); clone_subcommand clone(lg2_obj, app); commit_subcommand commit(lg2_obj, app); + config_subcommand config(lg2_obj, app); fetch_subcommand fetch(lg2_obj, app); reset_subcommand reset(lg2_obj, app); log_subcommand log(lg2_obj, app); diff --git a/src/subcommand/add_subcommand.cpp b/src/subcommand/add_subcommand.cpp index 51f57c1..e1aa4f4 100644 --- a/src/subcommand/add_subcommand.cpp +++ b/src/subcommand/add_subcommand.cpp @@ -9,7 +9,7 @@ add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app) { auto *sub = app.add_subcommand("add", "Add file contents to the index"); - sub->add_option("files", m_add_files, "Files to add"); + sub->add_option("", m_add_files, "Files to add"); sub->add_flag("-A,--all,--no-ignore-removal", m_all_flag, ""); // sub->add_flag("-n,--dryrun", dryrun_flag, ""); diff --git a/src/subcommand/config_subcommand.cpp b/src/subcommand/config_subcommand.cpp new file mode 100644 index 0000000..566366c --- /dev/null +++ b/src/subcommand/config_subcommand.cpp @@ -0,0 +1,100 @@ +#include +#include +#include + +#include + +#include "../utils/git_exception.hpp" +#include "../subcommand/config_subcommand.hpp" +#include "../wrapper/config_wrapper.hpp" +#include "../wrapper/repository_wrapper.hpp" + +config_subcommand::config_subcommand(const libgit2_object&, CLI::App& app) +{ + auto* config = app.add_subcommand("config", "Get and set repository or global options"); + auto* list = config->add_subcommand("list", "List all variables set in config file, along with their values."); + auto* get = config->add_subcommand("get", "Emits the value of the specified key. If key is present multiple times in the configuration, emits the last value. If --all is specified, emits all values associated with key. Returns error code 1 if key is not present."); + auto* set = config->add_subcommand("set", "Set value for one or more config options. By default, this command refuses to write multi-valued config options. Passing --all will replace all multi-valued config options with the new value, whereas --value= will replace all config options whose values match the given pattern."); + auto* unset = config->add_subcommand("unset", "Unset value for one or more config options. By default, this command refuses to unset multi-valued keys. Passing --all will unset all multi-valued config options, whereas --value will unset all config options whose values match the given pattern."); + + get->add_option("", m_name, ""); + set->add_option("", m_name, ""); + set->add_option("", m_value, ""); + unset->add_option("", m_name, ""); + + // sub->add_flag("--local", m_local_flag, ""); + // sub->add_flag("--global", m_global_flag, ""); + // sub->add_flag("--system", m_system_flag, ""); + // sub->add_flag("--worktree", m_worktree_flag, ""); + + list->callback([this]() { this->run_list(); }); + get->callback([this]() { this->run_get(); }); + set->callback([this]() { this->run_set(); }); + unset->callback([this]() { this->run_unset(); }); +} + +void config_subcommand::run_list() +{ + auto directory = get_current_git_path(); + auto repo = repository_wrapper::open(directory); + auto cfg = repo.get_config(); + + git_config_iterator* iter; + throw_if_error(git_config_iterator_new(&iter, cfg)); + + git_config_entry* entry; + while (git_config_next(&entry, iter)) + { + std::cout << entry->name << "=" << entry->value << std::endl; + } + + git_config_iterator_free(iter); +} + +void config_subcommand::run_get() +{ + if (m_name.empty()) + { + std::cout << "error: wrong number of arguments, should be 1" << std::endl; + return; + } + + auto directory = get_current_git_path(); + auto repo = repository_wrapper::open(directory); + auto cfg = repo.get_config(); + + git_config_entry* entry = cfg.get_entry(m_name); + std::cout << entry->value << std::endl; + + git_config_entry_free(entry); +} + +void config_subcommand::run_set() +{ + if (m_name.empty() | m_value.empty()) + { + std::cout << "error: wrong number of arguments, should be 2" << std::endl; + return; + } + + auto directory = get_current_git_path(); + auto repo = repository_wrapper::open(directory); + auto cfg = repo.get_config(); + + cfg.set_entry(m_name, m_value); +} + +void config_subcommand::run_unset() +{ + if (m_name.empty()) + { + std::cout << "error: wrong number of arguments, should be 1" << std::endl; + return; + } + + auto directory = get_current_git_path(); + auto repo = repository_wrapper::open(directory); + auto cfg = repo.get_config(); + + cfg.delete_entry(m_name); +} diff --git a/src/subcommand/config_subcommand.hpp b/src/subcommand/config_subcommand.hpp new file mode 100644 index 0000000..10905bd --- /dev/null +++ b/src/subcommand/config_subcommand.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "../utils/common.hpp" + +class config_subcommand +{ +public: + + explicit config_subcommand(const libgit2_object&, CLI::App& app); + void run_list(); + void run_set(); + void run_get(); + void run_unset(); + + std::string m_name; + std::string m_value; + // bool m_local_flag = false; + // bool m_global_flag = false; + // bool m_system_flag = false; + // bool m_worktree_flag = false; +}; diff --git a/src/wrapper/config_wrapper.cpp b/src/wrapper/config_wrapper.cpp new file mode 100644 index 0000000..4d947a7 --- /dev/null +++ b/src/wrapper/config_wrapper.cpp @@ -0,0 +1,30 @@ +#include "../wrapper/config_wrapper.hpp" +#include "../utils/git_exception.hpp" + +config_wrapper::config_wrapper(git_config* cfg) + : base_type(cfg) +{ +} + +config_wrapper::~config_wrapper() +{ + git_config_free(p_resource); + p_resource=nullptr; +} + +git_config_entry* config_wrapper::get_entry(std::string name) +{ + git_config_entry* entry; + throw_if_error(git_config_get_entry(&entry, *this, name.c_str())); + return entry; +} + +void config_wrapper::set_entry(std::string name, std::string value) +{ + throw_if_error(git_config_set_string(*this, name.c_str(), value.c_str())); +} + +void config_wrapper::delete_entry(std::string name) +{ + throw_if_error(git_config_delete_entry(*this, name.c_str())); +} diff --git a/src/wrapper/config_wrapper.hpp b/src/wrapper/config_wrapper.hpp new file mode 100644 index 0000000..124b7b0 --- /dev/null +++ b/src/wrapper/config_wrapper.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include + +#include "../wrapper/wrapper_base.hpp" + +class config_wrapper : public wrapper_base +{ +public: + + using base_type = wrapper_base; + + ~config_wrapper(); + + config_wrapper(config_wrapper&&) noexcept = default; + config_wrapper& operator=(config_wrapper&&) noexcept = default; + + git_config_entry* get_entry(std::string name); + void set_entry(std::string name, std::string value); + void delete_entry(std::string name); + +private: + + config_wrapper(git_config* cfg); + + friend class repository_wrapper; +}; diff --git a/src/wrapper/repository_wrapper.cpp b/src/wrapper/repository_wrapper.cpp index c945800..2dcfc47 100644 --- a/src/wrapper/repository_wrapper.cpp +++ b/src/wrapper/repository_wrapper.cpp @@ -1,6 +1,8 @@ +#include #include #include "../wrapper/repository_wrapper.hpp" +#include "config_wrapper.hpp" repository_wrapper::~repository_wrapper() { @@ -341,3 +343,12 @@ std::vector repository_wrapper::list_remotes() const git_strarray_dispose(&remotes); return result; } + + +// Config +config_wrapper repository_wrapper::get_config() +{ + git_config* cfg; + throw_if_error(git_repository_config(&cfg, *this)); + return config_wrapper(cfg); +} diff --git a/src/wrapper/repository_wrapper.hpp b/src/wrapper/repository_wrapper.hpp index 74e5eaa..9e332dd 100644 --- a/src/wrapper/repository_wrapper.hpp +++ b/src/wrapper/repository_wrapper.hpp @@ -10,6 +10,7 @@ #include "../wrapper/annotated_commit_wrapper.hpp" #include "../wrapper/branch_wrapper.hpp" #include "../wrapper/commit_wrapper.hpp" +#include "../wrapper/config_wrapper.hpp" #include "../wrapper/index_wrapper.hpp" #include "../wrapper/object_wrapper.hpp" #include "../wrapper/refs_wrapper.hpp" @@ -92,6 +93,9 @@ class repository_wrapper : public wrapper_base void set_remote_url(std::string_view name, std::string_view url, bool push = false); std::vector list_remotes() const; + // Config + config_wrapper get_config(); + private: repository_wrapper() = default; diff --git a/test/conftest.py b/test/conftest.py index aaf2ff5..1df7d90 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,7 +1,8 @@ import os +import subprocess from pathlib import Path + import pytest -import subprocess # Fixture to run test in current tmp_path @@ -22,12 +23,20 @@ def git2cpp_path(): def xtl_clone(git2cpp_path, tmp_path, run_in_tmp_path): url = "https://github.com/xtensor-stack/xtl.git" clone_cmd = [git2cpp_path, "clone", url] - subprocess.run(clone_cmd, capture_output=True, cwd=tmp_path, text=True) + p = subprocess.run(clone_cmd, capture_output=True, cwd=tmp_path, text=True) + assert p.returncode == 0 @pytest.fixture -def git_config(monkeypatch): +def commit_env_config(monkeypatch): monkeypatch.setenv("GIT_AUTHOR_NAME", "Jane Doe") monkeypatch.setenv("GIT_AUTHOR_EMAIL", "jane.doe@blabla.com") monkeypatch.setenv("GIT_COMMITTER_NAME", "Jane Doe") monkeypatch.setenv("GIT_COMMITTER_EMAIL", "jane.doe@blabla.com") + + +# @pytest.fixture +# def dump_config(tmp_path, run_in_tmp_path): +# p = tmp_path / ".gitconfig" +# p.write_text("user.name=Jane Doe") +# p.write_text("core.bare=true") diff --git a/test/test_commit.py b/test/test_commit.py index 1ed0018..7e21eb5 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -4,29 +4,33 @@ @pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"]) -def test_commit(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, all_flag): +def test_commit( + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch, all_flag +): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" p = xtl_path / "mook_file.txt" - p.write_text('') + p.write_text("") - cmd_add = [git2cpp_path, 'add', "mook_file.txt"] + cmd_add = [git2cpp_path, "add", "mook_file.txt"] p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True) assert p_add.returncode == 0 - cmd_status = [git2cpp_path, 'status', "--long"] + cmd_status = [git2cpp_path, "status", "--long"] p_status = subprocess.run(cmd_status, capture_output=True, cwd=xtl_path, text=True) assert p_status.returncode == 0 assert "Changes to be committed" in p_status.stdout assert "new file" in p_status.stdout - cmd_commit = [git2cpp_path, 'commit', "-m", "test commit"] + cmd_commit = [git2cpp_path, "commit", "-m", "test commit"] p_commit = subprocess.run(cmd_commit, cwd=xtl_path, text=True) assert p_commit.returncode == 0 - cmd_status_2 = [git2cpp_path, 'status', "--long"] - p_status_2 = subprocess.run(cmd_status_2, capture_output=True, cwd=xtl_path, text=True) + cmd_status_2 = [git2cpp_path, "status", "--long"] + p_status_2 = subprocess.run( + cmd_status_2, capture_output=True, cwd=xtl_path, text=True + ) assert p_status_2.returncode == 0 assert "mook_file" not in p_status_2.stdout diff --git a/test/test_config.py b/test/test_config.py new file mode 100644 index 0000000..1c94d19 --- /dev/null +++ b/test/test_config.py @@ -0,0 +1,72 @@ +import subprocess + +import pytest + + +def test_config_list(commit_env_config, git2cpp_path, tmp_path, monkeypatch): + cmd_init = [git2cpp_path, "init", "--bare", str(tmp_path)] + p_init = subprocess.run(cmd_init, capture_output=True) + assert p_init.returncode == 0 + + cmd_list = [git2cpp_path, "config", "list"] + p_list = subprocess.run(cmd_list, capture_output=True, cwd=tmp_path, text=True) + assert p_list.returncode == 0 + print(p_list.stdout) + assert "user.name=Jane Doe" in p_list.stdout + + +def test_config_get(git2cpp_path, tmp_path): + cmd_init = [git2cpp_path, "init", "--bare", str(tmp_path)] + p_init = subprocess.run(cmd_init, capture_output=True) + assert p_init.returncode == 0 + + cmd_get = [git2cpp_path, "config", "get", "core.bare"] + p_get = subprocess.run(cmd_get, cwd=tmp_path, text=True) + assert p_get.returncode == 0 + print(p_get.stdout) + assert p_get.stdout == "true" + + # cmd_get = [git2cpp_path, "config", "get", "user.name"] + # p_get = subprocess.run(cmd_get, cwd=tmp_path, text=True) + # assert p_get.returncode == 0 + # print(p_get.stdout) + # assert p_get.stdout == "Jane Doe" + + +def test_config_set(commit_env_config, git2cpp_path, tmp_path, monkeypatch): + cmd_init = [git2cpp_path, "init", "--bare", str(tmp_path)] + p_init = subprocess.run(cmd_init, capture_output=True) + assert p_init.returncode == 0 + + cmd_set_1 = [git2cpp_path, "config", "set", "user.name", "John Dough"] + p_set_1 = subprocess.run(cmd_set_1, cwd=tmp_path, text=True) + assert p_set_1.returncode == 0 + + cmd_get_1 = [git2cpp_path, "config", "get", "user.name"] + p_get_1 = subprocess.run(cmd_get_1, cwd=tmp_path, text=True) + assert p_get_1.returncode == 0 + assert p_get_1.stdout == "John Dough" + + cmd_set_2 = [git2cpp_path, "config", "set", "code.bare", "false"] + p_set_2 = subprocess.run(cmd_set_2, cwd=tmp_path, text=True) + assert p_set_2.returncode == 0 + + cmd_get_2 = [git2cpp_path, "config", "get", "code.bare"] + p_get_2 = subprocess.run(cmd_get_2, cwd=tmp_path, text=True) + assert p_get_2.returncode == 0 + assert p_get_2.stdout == "false" + + +def test_config_unset(commit_env_config, git2cpp_path, tmp_path, monkeypatch): + cmd_init = [git2cpp_path, "init", "--bare", str(tmp_path)] + p_init = subprocess.run(cmd_init, capture_output=True) + assert p_init.returncode == 0 + + cmd_unset = [git2cpp_path, "config", "unset", "user.name"] + p_unset = subprocess.run(cmd_unset, cwd=tmp_path, text=True) + assert p_unset.returncode == 0 + + cmd_get = [git2cpp_path, "config", "get", "user.name"] + p_get = subprocess.run(cmd_get, cwd=tmp_path, text=True) + assert p_get.returncode == 0 + assert p_get.stdout == "" diff --git a/test/test_log.py b/test/test_log.py index d7dae3d..53a9766 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -2,23 +2,26 @@ import pytest + @pytest.mark.parametrize("format_flag", ["", "--format=full", "--format=fuller"]) -def test_log(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, format_flag): +def test_log( + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch, format_flag +): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" p = xtl_path / "mook_file.txt" - p.write_text('') + p.write_text("") - cmd_add = [git2cpp_path, 'add', "mook_file.txt"] + cmd_add = [git2cpp_path, "add", "mook_file.txt"] p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True) assert p_add.returncode == 0 - cmd_commit = [git2cpp_path, 'commit', "-m", "test commit"] + cmd_commit = [git2cpp_path, "commit", "-m", "test commit"] p_commit = subprocess.run(cmd_commit, cwd=xtl_path, text=True) assert p_commit.returncode == 0 - cmd_log = [git2cpp_path, 'log'] + cmd_log = [git2cpp_path, "log"] if format_flag != "": cmd_log.append(format_flag) p_log = subprocess.run(cmd_log, capture_output=True, cwd=xtl_path, text=True) @@ -35,18 +38,21 @@ def test_log(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, format_ else: assert "CommitDate" in p_log.stdout -def test_log_nogit(git_config, git2cpp_path, tmp_path): - cmd_log = [git2cpp_path, 'log'] + +def test_log_nogit(commit_env_config, git2cpp_path, tmp_path): + cmd_log = [git2cpp_path, "log"] p_log = subprocess.run(cmd_log, capture_output=True, cwd=tmp_path, text=True) assert p_log.returncode != 0 @pytest.mark.parametrize("max_count_flag", ["", "-n", "--max-count"]) -def test_max_count(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, max_count_flag): +def test_max_count( + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch, max_count_flag +): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" - cmd_log = [git2cpp_path, 'log'] + cmd_log = [git2cpp_path, "log"] if max_count_flag != "": cmd_log.append(max_count_flag) cmd_log.append("2") diff --git a/test/test_merge.py b/test/test_merge.py index 0f531f0..f1510e8 100644 --- a/test/test_merge.py +++ b/test/test_merge.py @@ -5,7 +5,9 @@ # TODO: Have a different "person" for the commit and for the merge # TODO: Test "unborn" case, but how ? -def test_merge_fast_forward(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): +def test_merge_fast_forward( + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch +): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" @@ -52,7 +54,9 @@ def test_merge_fast_forward(xtl_clone, git_config, git2cpp_path, tmp_path, monke assert p_merge_2.stdout == "Already up-to-date\n" -def test_merge_commit(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): +def test_merge_commit( + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch +): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" @@ -115,7 +119,7 @@ def test_merge_commit(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch @pytest.mark.parametrize("flag", ["--abort", "--quit", "--continue"]) def test_merge_conflict( - xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, flag + xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch, flag ): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" diff --git a/test/test_remote.py b/test/test_remote.py index 6b302fb..d078701 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -389,7 +389,7 @@ def test_remote_show_in_cloned_repo(xtl_clone, git2cpp_path, tmp_path): assert "http" in p.stdout or "git" in p.stdout or "https" in p.stdout -def test_push_local(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): +def test_push_local(xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch): """Test setting push on a local remote.""" assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" diff --git a/test/test_reset.py b/test/test_reset.py index 3b86a1d..80f01fb 100644 --- a/test/test_reset.py +++ b/test/test_reset.py @@ -3,22 +3,22 @@ import pytest -def test_reset(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): +def test_reset(xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl" p = xtl_path / "mook_file.txt" - p.write_text('') + p.write_text("") - cmd_add = [git2cpp_path, 'add', "mook_file.txt"] + cmd_add = [git2cpp_path, "add", "mook_file.txt"] p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True) assert p_add.returncode == 0 - cmd_commit = [git2cpp_path, 'commit', "-m", "test commit"] + cmd_commit = [git2cpp_path, "commit", "-m", "test commit"] p_commit = subprocess.run(cmd_commit, cwd=xtl_path, text=True) assert p_commit.returncode == 0 - cmd_log = [git2cpp_path, 'log'] + cmd_log = [git2cpp_path, "log"] p_log = subprocess.run(cmd_log, capture_output=True, cwd=xtl_path, text=True) assert p_log.returncode == 0 assert "Jane Doe" in p_log.stdout @@ -27,13 +27,13 @@ def test_reset(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=xtl_path, text=True) assert p_reset.returncode == 0 - cmd_log_2 = [git2cpp_path, 'log'] + cmd_log_2 = [git2cpp_path, "log"] p_log = subprocess.run(cmd_log_2, capture_output=True, cwd=xtl_path, text=True) assert p_log.returncode == 0 assert "Jane Doe" not in p_log.stdout + def test_reset_nogit(git2cpp_path, tmp_path): cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"] p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True) assert p_reset.returncode != 0 - diff --git a/test/test_revlist.py b/test/test_revlist.py index 870b041..34e1f58 100644 --- a/test/test_revlist.py +++ b/test/test_revlist.py @@ -3,7 +3,7 @@ import pytest -def test_revlist(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): +def test_revlist(xtl_clone, commit_env_config, git2cpp_path, tmp_path, monkeypatch): assert (tmp_path / "xtl").exists() xtl_path = tmp_path / "xtl"