@@ -774,6 +774,7 @@ static int cmd_clone(int argc, const char **argv)
774774 const char * cache_server_url = NULL , * local_cache_root = NULL ;
775775 char * default_cache_server_url = NULL , * local_cache_root_abs = NULL ;
776776 int gvfs_protocol = -1 ;
777+ const char * ref_format = NULL ;
777778
778779 struct option clone_options [] = {
779780 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
@@ -797,18 +798,22 @@ static int cmd_clone(int argc, const char **argv)
797798 OPT_STRING (0 , "local-cache-path" , & local_cache_root ,
798799 N_ ("<path>" ),
799800 N_ ("override the path for the local Scalar cache" )),
801+ OPT_STRING (0 , "ref-format" , & ref_format , N_ ("format" ),
802+ N_ ("specify the reference format to use" )),
800803 OPT_HIDDEN_BOOL (0 , "no-fetch-commits-and-trees" ,
801804 & dummy , N_ ("no longer used" )),
802805 OPT_END (),
803806 };
804807 const char * const clone_usage [] = {
805808 N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
806- "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
809+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
810+ "\t<url> [<enlistment>]" ),
807811 NULL
808812 };
809813 const char * url ;
810814 char * enlistment = NULL , * dir = NULL ;
811815 struct strbuf buf = STRBUF_INIT ;
816+ struct strvec init_argv = STRVEC_INIT ;
812817 int res ;
813818
814819 argc = parse_options (argc , argv , NULL , clone_options , clone_usage , 0 );
@@ -856,16 +861,26 @@ static int cmd_clone(int argc, const char **argv)
856861 if (!local_cache_root )
857862 die (_ ("could not determine local cache root" ));
858863
859- strbuf_reset (& buf );
864+ strvec_clear (& init_argv );
865+ strvec_pushf (& init_argv , "-c" );
860866 if (branch )
861- strbuf_addf ( & buf , "init.defaultBranch=%s" , branch );
867+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , branch );
862868 else {
863869 char * b = repo_default_branch_name (the_repository , 1 );
864- strbuf_addf ( & buf , "init.defaultBranch=%s" , b );
870+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , b );
865871 free (b );
866872 }
867873
868- if ((res = run_git ("-c" , buf .buf , "init" , "--" , dir , NULL )))
874+ strvec_push (& init_argv , "init" );
875+
876+ if (ref_format ) {
877+ strvec_push (& init_argv , "--ref-format" );
878+ strvec_push (& init_argv , ref_format );
879+ }
880+
881+ strvec_push (& init_argv , "--" );
882+ strvec_push (& init_argv , dir );
883+ if ((res = run_git_argv (& init_argv )))
869884 goto cleanup ;
870885
871886 if (chdir (dir ) < 0 ) {
@@ -1015,6 +1030,7 @@ static int cmd_clone(int argc, const char **argv)
10151030 free (enlistment );
10161031 free (dir );
10171032 strbuf_release (& buf );
1033+ strvec_clear (& init_argv );
10181034 free (default_cache_server_url );
10191035 free (local_cache_root_abs );
10201036 return res ;
0 commit comments