2626#include "run-command.h"
2727#include "connected.h"
2828#include "packfile.h"
29+ #include "list-objects-filter-options.h"
2930
3031/*
3132 * Overall FIXMEs:
@@ -60,6 +61,7 @@ static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
6061static int option_dissociate ;
6162static int max_jobs = -1 ;
6263static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP ;
64+ static struct list_objects_filter_options filter_options ;
6365
6466static int recurse_submodules_cb (const struct option * opt ,
6567 const char * arg , int unset )
@@ -135,6 +137,7 @@ static struct option builtin_clone_options[] = {
135137 TRANSPORT_FAMILY_IPV4 ),
136138 OPT_SET_INT ('6' , "ipv6" , & family , N_ ("use IPv6 addresses only" ),
137139 TRANSPORT_FAMILY_IPV6 ),
140+ OPT_PARSE_LIST_OBJECTS_FILTER (& filter_options ),
138141 OPT_END ()
139142};
140143
@@ -886,6 +889,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
886889 struct refspec * refspec ;
887890 const char * fetch_pattern ;
888891
892+ fetch_if_missing = 0 ;
893+
889894 packet_trace_identity ("clone" );
890895 argc = parse_options (argc , argv , prefix , builtin_clone_options ,
891896 builtin_clone_usage , 0 );
@@ -1073,6 +1078,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10731078 warning (_ ("--shallow-since is ignored in local clones; use file:// instead." ));
10741079 if (option_not .nr )
10751080 warning (_ ("--shallow-exclude is ignored in local clones; use file:// instead." ));
1081+ if (filter_options .choice )
1082+ warning (_ ("--filter is ignored in local clones; use file:// instead." ));
10761083 if (!access (mkpath ("%s/shallow" , path ), F_OK )) {
10771084 if (option_local > 0 )
10781085 warning (_ ("source repository is shallow, ignoring --local" ));
@@ -1104,7 +1111,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11041111 transport_set_option (transport , TRANS_OPT_UPLOADPACK ,
11051112 option_upload_pack );
11061113
1107- if (transport -> smart_options && !deepen )
1114+ if (filter_options .choice ) {
1115+ transport_set_option (transport , TRANS_OPT_LIST_OBJECTS_FILTER ,
1116+ filter_options .filter_spec );
1117+ transport_set_option (transport , TRANS_OPT_FROM_PROMISOR , "1" );
1118+ }
1119+
1120+ if (transport -> smart_options && !deepen && !filter_options .choice )
11081121 transport -> smart_options -> check_self_contained_and_connected = 1 ;
11091122
11101123 refs = transport_get_remote_refs (transport );
@@ -1164,13 +1177,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11641177 write_refspec_config (src_ref_prefix , our_head_points_at ,
11651178 remote_head_points_at , & branch_top );
11661179
1180+ if (filter_options .choice )
1181+ partial_clone_register ("origin" , & filter_options );
1182+
11671183 if (is_local )
11681184 clone_local (path , git_dir );
11691185 else if (refs && complete_refs_before_fetch )
11701186 transport_fetch_refs (transport , mapped_refs );
11711187
11721188 update_remote_refs (refs , mapped_refs , remote_head_points_at ,
1173- branch_top .buf , reflog_msg .buf , transport , !is_local );
1189+ branch_top .buf , reflog_msg .buf , transport ,
1190+ !is_local && !filter_options .choice );
11741191
11751192 update_head (our_head_points_at , remote_head , reflog_msg .buf );
11761193
@@ -1191,6 +1208,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11911208 }
11921209
11931210 junk_mode = JUNK_LEAVE_REPO ;
1211+ fetch_if_missing = 1 ;
11941212 err = checkout (submodule_progress );
11951213
11961214 strbuf_release (& reflog_msg );
0 commit comments