Skip to content

Commit 1be6891

Browse files
committed
Fixed depth=0
1 parent 4dcabb7 commit 1be6891

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/subcommand/clone_subcommand.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ clone_subcommand::clone_subcommand(const libgit2_object&, CLI::App& app)
2121

2222
void clone_subcommand::run()
2323
{
24+
// m_depth = 0 means no shallow clone in libgit2, while
25+
// it is forbidden with git. Therefore we use another
26+
// sentinel value to detect full clone.
27+
if (m_depth == 0)
28+
{
29+
std::cout << "fatal: depth 0 is not a positive number" << std::endl;
30+
return;
31+
}
32+
33+
if (m_depth == std::numeric_limits<size_t>::max())
34+
{
35+
m_depth = 0;
36+
}
37+
2438
git_indexer_progress pd;
2539
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
2640
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
@@ -34,8 +48,6 @@ void clone_subcommand::run()
3448
clone_opts.fetch_opts.depth = m_depth;
3549
clone_opts.bare = m_bare ? 1 : 0;
3650

37-
38-
3951
std::string short_name = m_directory;
4052
if (m_directory.empty())
4153
{

src/subcommand/clone_subcommand.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <CLI/CLI.hpp>
4+
#include <limits>
45

56
#include "../utils/common.hpp"
67

@@ -16,7 +17,7 @@ class clone_subcommand
1617
std::string m_repository = {};
1718
std::string m_directory = {};
1819
bool m_bare = false;
19-
size_t m_depth = 0;
20+
size_t m_depth = std::numeric_limits<size_t>::max();
2021
// std::string m_shallow_since;
2122
// std::vector<std::string> m_shallow_exclude;
2223
};

0 commit comments

Comments
 (0)