Skip to content

Commit 4dcabb7

Browse files
committed
Fixed depth=1
1 parent dded9a6 commit 4dcabb7

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/wrapper/repository_wrapper.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,9 @@ void repository_wrapper::reset(const object_wrapper& target, git_reset_t reset_t
285285

286286
size_t repository_wrapper::shallow_depth_from_head() const
287287
{
288-
size_t depth = 0;
289288
if (!this->is_shallow())
290289
{
291-
return depth;
290+
return 0u;
292291
}
293292

294293
std::string git_path = this->git_path();
@@ -307,44 +306,44 @@ size_t repository_wrapper::shallow_depth_from_head() const
307306
}
308307
}
309308

310-
if (boundaries_list.size()==0)
309+
if (boundaries_list.size() == 0u)
311310
{
312-
return depth;
311+
return 0u;
313312
}
314313

315314
commit_wrapper head_commit = this->find_commit("HEAD");
316315
commit_list_wrapper commits_list = head_commit.get_parents_list();
317-
std::vector<size_t> depth_list(commits_list.size(), 0);
318-
std::vector<size_t> final_depths(boundaries_list.size(), 0);
319-
bool has_parent = commits_list.size() > 0;
316+
std::vector<size_t> depth_list(commits_list.size(), 1u);
317+
std::vector<size_t> final_depths(boundaries_list.size(), 1u);
318+
bool has_parent = commits_list.size() > 0u;
320319
while (has_parent)
321320
{
322321
has_parent = false;
323322
std::vector<commit_wrapper> temp_commits_list;
324323
std::vector<size_t> temp_depth_list;
325324
commit_list_wrapper parent_list({});
326325

327-
for (size_t i = 0; i < commits_list.size(); i++)
326+
for (size_t i = 0u; i < commits_list.size(); i++)
328327
{
329328
const commit_wrapper& commit = commits_list[i];
330329
size_t depth = depth_list[i];
331330
const git_oid& oid = commit.oid();
332331
bool is_boundary = std::find_if(boundaries_list.cbegin(), boundaries_list.cend(), [oid](const git_oid& val) {return git_oid_equal(&oid, &val);}) != boundaries_list.cend();
333332
if (is_boundary)
334333
{
335-
final_depths.push_back(depth + 1);
334+
final_depths.push_back(depth + 1u);
336335
}
337336
else
338337
{
339338
parent_list = commit.get_parents_list();
340-
if (parent_list.size() > 0)
339+
if (parent_list.size() > 0u)
341340
{
342341
has_parent = true;
343-
for (size_t j = 0; parent_list.size(); j++)
342+
for (size_t j = 0u; parent_list.size(); j++)
344343
{
345344
const commit_wrapper& c = parent_list[j];
346345
temp_commits_list.push_back(std::move(const_cast<commit_wrapper&>(c)));
347-
temp_depth_list.push_back(depth + 1);
346+
temp_depth_list.push_back(depth + 1u);
348347
}
349348
}
350349
}
@@ -353,7 +352,7 @@ size_t repository_wrapper::shallow_depth_from_head() const
353352
commits_list = commit_list_wrapper(std::move(temp_commits_list));
354353
}
355354

356-
depth = *std::max_element(final_depths.begin(), final_depths.end());
355+
std::size_t depth = *std::max_element(final_depths.begin(), final_depths.end());
357356
return depth;
358357
}
359358

test/test_remote.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ def test_fetch_default_origin(git2cpp_path, repo_with_remote):
319319

320320
def test_fetch_depth(git2cpp_path, tmp_path, run_in_tmp_path):
321321
url = "https://github.com/xtensor-stack/xtl.git"
322+
323+
invalid_clone_cmd = [git2cpp_path, "clone", "--depth", "0", url]
324+
p_invalid_clone = subprocess.run(invalid_clone_cmd, capture_output=True, cwd=tmp_path, text=True)
325+
assert p_invalid_clone.returncode != 0
326+
322327
clone_cmd = [git2cpp_path, "clone", "--depth", "1", url]
323328
p_clone = subprocess.run(clone_cmd, capture_output=True, cwd=tmp_path, text=True)
324329
assert p_clone.returncode == 0

0 commit comments

Comments
 (0)