1818
1919#define COMMAND_NAME "clone"
2020
21- static char * branch , * remote_path , * local_path ;
21+ static char * branch , * remote_path , * local_path , * depth ;
2222static int show_help , quiet , checkout = 1 , bare ;
2323static bool local_path_exists ;
2424static cli_progress progress = CLI_PROGRESS_INIT ;
@@ -36,6 +36,8 @@ static const cli_opt_spec opts[] = {
3636 CLI_OPT_USAGE_DEFAULT , NULL , "don't create a working directory" },
3737 { CLI_OPT_TYPE_VALUE , "branch" , 'b' , & branch , 0 ,
3838 CLI_OPT_USAGE_DEFAULT , "name" , "branch to check out" },
39+ { CLI_OPT_TYPE_VALUE , "depth" , 0 , & depth , 0 ,
40+ CLI_OPT_USAGE_DEFAULT , "depth" , "commit depth to check out " },
3941 { CLI_OPT_TYPE_LITERAL },
4042 { CLI_OPT_TYPE_ARG , "repository" , 0 , & remote_path , 0 ,
4143 CLI_OPT_USAGE_REQUIRED , "repository" , "repository path" },
@@ -71,6 +73,22 @@ static char *compute_local_path(const char *orig_path)
7173 return local_path ;
7274}
7375
76+ static int compute_depth (const char * depth )
77+ {
78+ int64_t i ;
79+ const char * endptr ;
80+
81+ if (!depth )
82+ return 0 ;
83+
84+ if (git__strntol64 (& i , depth , strlen (depth ), & endptr , 10 ) < 0 || i < 0 || i > INT_MAX || * endptr ) {
85+ fprintf (stderr , "fatal: depth '%s' is not valid.\n" , depth );
86+ exit (128 );
87+ }
88+
89+ return (int )i ;
90+ }
91+
7492static bool validate_local_path (const char * path )
7593{
7694 if (!git_fs_path_exists (path ))
@@ -127,11 +145,9 @@ int cmd_clone(int argc, char **argv)
127145 goto done ;
128146 }
129147
130- if (bare )
131- clone_opts .bare = 1 ;
132-
133- if (branch )
134- clone_opts .checkout_branch = branch ;
148+ clone_opts .bare = !!bare ;
149+ clone_opts .checkout_branch = branch ;
150+ clone_opts .fetch_opts .depth = compute_depth (depth );
135151
136152 if (!checkout )
137153 clone_opts .checkout_opts .checkout_strategy = GIT_CHECKOUT_NONE ;
0 commit comments