Skip to content

Commit f4d6839

Browse files
committed
Fix default directory in git init
1 parent 22780bc commit f4d6839

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/subcommand/init_subcommand.cpp‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app)
1616
m_directory,
1717
"Directory to create the repository in, created if it does not exist. Defaults to the current directory."
1818
)
19-
->check(CLI::ExistingDirectory | CLI::NonexistentPath)
20-
->default_val(get_current_git_path());
19+
->check(CLI::ExistingDirectory | CLI::NonexistentPath);
20+
2121
sub->add_option(
2222
"-b,--initial-branch",
2323
m_branch,
@@ -34,6 +34,11 @@ init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app)
3434

3535
void init_subcommand::run()
3636
{
37+
if (m_directory.empty())
38+
{
39+
m_directory = get_current_git_path();
40+
}
41+
3742
std::filesystem::path target_dir = m_directory;
3843
bool reinit = std::filesystem::exists(target_dir / ".git" / "HEAD");
3944

‎test/test_init.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,11 @@ def test_init_filemode(git2cpp_path, tmp_path):
186186
assert filemode_lines == ["core.filemode=false", "core.filemode=false"]
187187
else:
188188
assert filemode_lines == ["core.filemode=false"]
189+
190+
191+
def test_init_help_has_no_default_directory(git2cpp_path, tmp_path, run_in_tmp_path):
192+
cmd = [git2cpp_path, "init", "--help"]
193+
p = subprocess.run(cmd, capture_output=True, text=True)
194+
assert p.returncode == 0
195+
assert "directory" in p.stdout
196+
assert str(tmp_path) not in p.stdout

0 commit comments

Comments
 (0)