From 4a067bb1de2bc2e7e5554e97e0cddc988fe0a3ad Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Thu, 27 Nov 2025 10:03:21 +0000 Subject: [PATCH] Initialise m_bare flag in init subcommand --- src/subcommand/init_subcommand.hpp | 2 +- test/test_init.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/subcommand/init_subcommand.hpp b/src/subcommand/init_subcommand.hpp index 6086492..9fb9ffc 100644 --- a/src/subcommand/init_subcommand.hpp +++ b/src/subcommand/init_subcommand.hpp @@ -14,6 +14,6 @@ class init_subcommand void run(); private: - bool m_bare; + bool m_bare = false; std::string m_directory; }; diff --git a/test/test_init.py b/test/test_init.py index fa23ebf..aec88a0 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -37,7 +37,29 @@ def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path): # TODO: check this is a valid git repo -# TODO: Test without bare flag. +def test_init_not_bare(git2cpp_path, tmp_path): + # tmp_path exists and is empty. + assert list(tmp_path.iterdir()) == [] + + cmd = [git2cpp_path, 'init', '.'] + p = subprocess.run(cmd, capture_output=True, cwd=tmp_path) + assert p.returncode == 0 + assert p.stdout == b'' + assert p.stderr == b'' + + # Directory contains just .git directory. + assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == ['.git'] + # .git directory is a valid repo. + assert sorted(map(lambda path: path.name, (tmp_path / '.git').iterdir())) == [ + 'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs' + ] + + # Would like to use `git2cpp status` but it complains that 'refs/heads/master' not found + cmd = [git2cpp_path, 'log'] + p = subprocess.run(cmd, capture_output=True, cwd=tmp_path) + assert p.returncode == 0 + assert p.stdout == b'' + assert p.stderr == b'' def test_error_on_unknown_option(git2cpp_path):