Skip to content

Commit bbfda5b

Browse files
committed
address review comments
1 parent f6924a9 commit bbfda5b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/subcommand/init_subcommand.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ void init_subcommand::run()
3131
else
3232
{
3333
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
34-
if (m_bare) {opts.flags |= GIT_REPOSITORY_INIT_BARE;}
34+
if (m_bare)
35+
{
36+
opts.flags |= GIT_REPOSITORY_INIT_BARE;
37+
}
3538
opts.initial_head = m_branch.c_str();
3639

3740
auto repo = repository_wrapper::init_ext(m_directory, &opts);
@@ -42,7 +45,14 @@ void init_subcommand::run()
4245
if (m_bare)
4346
{
4447
size_t pos = git_path.find(".git/");
45-
path = git_path.substr(0, pos);
48+
if (pos != std::string::npos)
49+
{
50+
path = git_path.substr(0, pos);
51+
}
52+
else
53+
{
54+
throw git_exception("'.git/' not found in the path of the repository.", git2cpp_error_code::FILESYSTEM_ERROR);
55+
}
4656
}
4757
else
4858
{

0 commit comments

Comments
 (0)