@@ -49,6 +49,7 @@ static int option_verbosity;
4949static int option_progress = -1 ;
5050static struct string_list option_config ;
5151static struct string_list option_reference ;
52+ static int option_dissociate ;
5253
5354static int opt_parse_reference (const struct option * opt , const char * arg , int unset )
5455{
@@ -94,6 +95,8 @@ static struct option builtin_clone_options[] = {
9495 N_ ("create a shallow clone of that depth" )),
9596 OPT_BOOL (0 , "single-branch" , & option_single_branch ,
9697 N_ ("clone only one branch, HEAD or --branch" )),
98+ OPT_BOOL (0 , "dissociate" , & option_dissociate ,
99+ N_ ("use --reference only while cloning" )),
97100 OPT_STRING (0 , "separate-git-dir" , & real_git_dir , N_ ("gitdir" ),
98101 N_ ("separate git dir from working tree" )),
99102 OPT_STRING_LIST ('c' , "config" , & option_config , N_ ("key=value" ),
@@ -735,6 +738,16 @@ static void write_refspec_config(const char *src_ref_prefix,
735738 strbuf_release (& value );
736739}
737740
741+ static void dissociate_from_references (void )
742+ {
743+ static const char * argv [] = { "repack" , "-a" , "-d" , NULL };
744+
745+ if (run_command_v_opt (argv , RUN_GIT_CMD |RUN_COMMAND_NO_STDIN ))
746+ die (_ ("cannot repack to clean up" ));
747+ if (unlink (git_path ("objects/info/alternates" )) && errno != ENOENT )
748+ die_errno (_ ("cannot unlink temporary alternates file" ));
749+ }
750+
738751int cmd_clone (int argc , const char * * argv , const char * prefix )
739752{
740753 int is_bundle = 0 , is_local ;
@@ -880,6 +893,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
880893
881894 if (option_reference .nr )
882895 setup_reference ();
896+ else if (option_dissociate ) {
897+ warning (_ ("--dissociate given, but there is no --reference" ));
898+ option_dissociate = 0 ;
899+ }
883900
884901 fetch_pattern = value .buf ;
885902 refspec = parse_fetch_refspec (1 , & fetch_pattern );
@@ -993,6 +1010,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
9931010 transport_unlock_pack (transport );
9941011 transport_disconnect (transport );
9951012
1013+ if (option_dissociate )
1014+ dissociate_from_references ();
1015+
9961016 junk_mode = JUNK_LEAVE_REPO ;
9971017 err = checkout ();
9981018
0 commit comments