Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
address review comments
  • Loading branch information
SandrineP committed Mar 13, 2026
commit deb2b86e1c27eb4d57a2314ca9f67fb77ed2ef32
22 changes: 7 additions & 15 deletions src/subcommand/init_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,23 @@ void init_subcommand::run()
std::filesystem::path target_dir = m_directory;
bool reinit = std::filesystem::exists(target_dir / ".git" / "HEAD");

std::string git_path;
std::string path;
if (m_branch.empty())
{
auto repo = repository_wrapper::init(m_directory, m_bare);
git_path = repo.git_path();
path = repo.path();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is now that same here and in the else branch below, so it could be moved outside the end of the if-else.

Copy link
Copy Markdown
Collaborator Author

@SandrineP SandrineP Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't, because the repo doesn't exist outside of the if-else. I tried to change that using something like repository_wrapper repo = [this](){if-else}() but there was a problem with the init then.
I gave it anohter try and it seem to work.

}
else
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
if (m_bare) {opts.flags |= GIT_REPOSITORY_INIT_BARE;}
if (m_bare)
{
opts.flags |= GIT_REPOSITORY_INIT_BARE;
}
opts.initial_head = m_branch.c_str();

auto repo = repository_wrapper::init_ext(m_directory, &opts);
git_path = repo.git_path();
}

std::string path;
if (m_bare)
{
size_t pos = git_path.find(".git/");
path = git_path.substr(0, pos);
}
else
{
path = git_path;
path = repo.path();
}

if (reinit)
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repository_wrapper repository_wrapper::clone(std::string_view url, std::string_v
return rw;
}

std::string repository_wrapper::git_path() const
std::string repository_wrapper::path() const
{
return git_repository_path(*this);
}
Expand Down Expand Up @@ -350,8 +350,8 @@ size_t repository_wrapper::shallow_depth_from_head() const
return 0u;
}

std::string git_path = this->git_path();
std::string shallow_path = git_path + "shallow";
std::string path = this->path();
std::string shallow_path = path + "shallow";

std::vector<git_oid> boundaries_list;
std::ifstream f(shallow_path);
Expand Down
2 changes: 1 addition & 1 deletion src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class repository_wrapper : public wrapper_base<git_repository>
static repository_wrapper open(std::string_view directory);
static repository_wrapper clone(std::string_view url, std::string_view path, const git_clone_options& opts);

std::string git_path() const;
std::string path() const;
git_repository_state_t state() const;
void state_cleanup();

Expand Down
Loading