Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/subcommand/init_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app)
m_directory,
"Directory to create the repository in, created if it does not exist. Defaults to the current directory."
)
->check(CLI::ExistingDirectory | CLI::NonexistentPath)
->default_val(get_current_git_path());
->check(CLI::ExistingDirectory | CLI::NonexistentPath);

sub->add_option(
"-b,--initial-branch",
m_branch,
Expand All @@ -34,6 +34,11 @@ init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app)

void init_subcommand::run()
{
if (m_directory.empty())
{
m_directory = get_current_git_path();
}

std::filesystem::path target_dir = m_directory;
bool reinit = std::filesystem::exists(target_dir / ".git" / "HEAD");

Expand Down
8 changes: 8 additions & 0 deletions test/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@ def test_init_filemode(git2cpp_path, tmp_path):
assert filemode_lines == ["core.filemode=false", "core.filemode=false"]
else:
assert filemode_lines == ["core.filemode=false"]


def test_init_help_has_no_default_directory(git2cpp_path, tmp_path, run_in_tmp_path):
cmd = [git2cpp_path, "init", "--help"]
p = subprocess.run(cmd, capture_output=True, text=True)
assert p.returncode == 0
assert "directory" in p.stdout
assert str(tmp_path) not in p.stdout
Loading