Skip to content

Commit 9e6938b

Browse files
authored
Initialise m_bare flag in init subcommand (#56)
1 parent 6667003 commit 9e6938b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/subcommand/init_subcommand.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class init_subcommand
1414
void run();
1515

1616
private:
17-
bool m_bare;
17+
bool m_bare = false;
1818
std::string m_directory;
1919
};

test/test_init.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,29 @@ def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path):
3737
# TODO: check this is a valid git repo
3838

3939

40-
# TODO: Test without bare flag.
40+
def test_init_not_bare(git2cpp_path, tmp_path):
41+
# tmp_path exists and is empty.
42+
assert list(tmp_path.iterdir()) == []
43+
44+
cmd = [git2cpp_path, 'init', '.']
45+
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path)
46+
assert p.returncode == 0
47+
assert p.stdout == b''
48+
assert p.stderr == b''
49+
50+
# Directory contains just .git directory.
51+
assert sorted(map(lambda path: path.name, tmp_path.iterdir())) == ['.git']
52+
# .git directory is a valid repo.
53+
assert sorted(map(lambda path: path.name, (tmp_path / '.git').iterdir())) == [
54+
'HEAD', 'config', 'description', 'hooks', 'info', 'objects', 'refs'
55+
]
56+
57+
# Would like to use `git2cpp status` but it complains that 'refs/heads/master' not found
58+
cmd = [git2cpp_path, 'log']
59+
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path)
60+
assert p.returncode == 0
61+
assert p.stdout == b''
62+
assert p.stderr == b''
4163

4264

4365
def test_error_on_unknown_option(git2cpp_path):

0 commit comments

Comments
 (0)