diff --git a/src/subcommand/add_subcommand.cpp b/src/subcommand/add_subcommand.cpp index 9988d25..51f57c1 100644 --- a/src/subcommand/add_subcommand.cpp +++ b/src/subcommand/add_subcommand.cpp @@ -23,8 +23,7 @@ add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app) void add_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; - auto repo = repository_wrapper::init(directory, bare); + auto repo = repository_wrapper::open(directory); index_wrapper index = repo.make_index(); diff --git a/src/subcommand/commit_subcommand.cpp b/src/subcommand/commit_subcommand.cpp index e70f424..d281ec6 100644 --- a/src/subcommand/commit_subcommand.cpp +++ b/src/subcommand/commit_subcommand.cpp @@ -19,8 +19,7 @@ commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app) void commit_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; - auto repo = repository_wrapper::init(directory, bare); + auto repo = repository_wrapper::open(directory); auto author_committer_signatures = signature_wrapper::get_default_signature_from_env(repo); if (m_commit_message.empty()) diff --git a/src/subcommand/log_subcommand.cpp b/src/subcommand/log_subcommand.cpp index c25e270..490569b 100644 --- a/src/subcommand/log_subcommand.cpp +++ b/src/subcommand/log_subcommand.cpp @@ -80,8 +80,7 @@ void print_commit(const commit_wrapper& commit, std::string m_format_flag) void log_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; - auto repo = repository_wrapper::init(directory, bare); + auto repo = repository_wrapper::open(directory); // auto branch_name = repo.head().short_name(); git_revwalk* walker; diff --git a/src/subcommand/reset_subcommand.cpp b/src/subcommand/reset_subcommand.cpp index b862e78..61fa0ae 100644 --- a/src/subcommand/reset_subcommand.cpp +++ b/src/subcommand/reset_subcommand.cpp @@ -27,8 +27,7 @@ reset_subcommand::reset_subcommand(const libgit2_object&, CLI::App& app) void reset_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; - auto repo = repository_wrapper::init(directory, bare); + auto repo = repository_wrapper::open(directory); auto target = repo.revparse_single(m_commit); if (!target) diff --git a/src/subcommand/status_subcommand.cpp b/src/subcommand/status_subcommand.cpp index 83ebd6d..88a8783 100644 --- a/src/subcommand/status_subcommand.cpp +++ b/src/subcommand/status_subcommand.cpp @@ -183,8 +183,7 @@ void print_not_tracked(const std::vector& entries_to_print, const s void status_subcommand::run() { auto directory = get_current_git_path(); - auto bare = false; - auto repo = repository_wrapper::init(directory, bare); + auto repo = repository_wrapper::open(directory); auto sl = status_list_wrapper::status_list(repo); auto branch_name = repo.head().short_name(); diff --git a/test/test_add.py b/test/test_add.py index a5055e8..a772779 100644 --- a/test/test_add.py +++ b/test/test_add.py @@ -32,3 +32,11 @@ def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag): assert "Untracked files" not in p_status.stdout else: assert "Untracked files" in p_status.stdout + +def test_add_nogit(git2cpp_path, tmp_path): + p = tmp_path / "mook_file.txt" + p.write_text('') + + cmd_add = [git2cpp_path, 'add', 'mook_file.txt'] + p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True) + assert p_add.returncode != 0 diff --git a/test/test_branch.py b/test/test_branch.py index 4e1f9fe..f81bc8c 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -33,3 +33,8 @@ def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path): p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True) assert p_list2.returncode == 0 assert(p_list2.stdout == '* master\n') + +def test_branch_nogit(git2cpp_path, tmp_path): + cmd = [git2cpp_path, 'branch'] + p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) + assert p.returncode != 0 diff --git a/test/test_log.py b/test/test_log.py index 659c7a4..d7dae3d 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -35,6 +35,11 @@ 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'] + 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): diff --git a/test/test_reset.py b/test/test_reset.py index 74e9aa1..3b86a1d 100644 --- a/test/test_reset.py +++ b/test/test_reset.py @@ -31,3 +31,9 @@ def test_reset(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch): 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_status.py b/test/test_status.py index cfacb7b..ab7288e 100644 --- a/test/test_status.py +++ b/test/test_status.py @@ -38,6 +38,10 @@ def test_status_new_file(xtl_clone, git2cpp_path, tmp_path, short_flag, long_fla assert " D " in p.stdout assert "?? " in p.stdout +def test_status_nogit(git2cpp_path, tmp_path): + cmd = [git2cpp_path, 'status'] + p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) + assert p.returncode != 0 @pytest.mark.parametrize("short_flag", ["", "-s", "--short"]) @pytest.mark.parametrize("long_flag", ["", "--long"])