@@ -773,6 +773,7 @@ static int cmd_clone(int argc, const char **argv)
773773 const char * cache_server_url = NULL , * local_cache_root = NULL ;
774774 char * default_cache_server_url = NULL , * local_cache_root_abs = NULL ;
775775 int gvfs_protocol = -1 ;
776+ const char * ref_format = NULL ;
776777
777778 struct option clone_options [] = {
778779 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
@@ -796,18 +797,22 @@ static int cmd_clone(int argc, const char **argv)
796797 OPT_STRING (0 , "local-cache-path" , & local_cache_root ,
797798 N_ ("<path>" ),
798799 N_ ("override the path for the local Scalar cache" )),
800+ OPT_STRING (0 , "ref-format" , & ref_format , N_ ("format" ),
801+ N_ ("specify the reference format to use" )),
799802 OPT_HIDDEN_BOOL (0 , "no-fetch-commits-and-trees" ,
800803 & dummy , N_ ("no longer used" )),
801804 OPT_END (),
802805 };
803806 const char * const clone_usage [] = {
804807 N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
805- "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
808+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
809+ "\t<url> [<enlistment>]" ),
806810 NULL
807811 };
808812 const char * url ;
809813 char * enlistment = NULL , * dir = NULL ;
810814 struct strbuf buf = STRBUF_INIT ;
815+ struct strvec init_argv = STRVEC_INIT ;
811816 int res ;
812817
813818 argc = parse_options (argc , argv , NULL , clone_options , clone_usage , 0 );
@@ -855,16 +860,26 @@ static int cmd_clone(int argc, const char **argv)
855860 if (!local_cache_root )
856861 die (_ ("could not determine local cache root" ));
857862
858- strbuf_reset (& buf );
863+ strvec_clear (& init_argv );
864+ strvec_pushf (& init_argv , "-c" );
859865 if (branch )
860- strbuf_addf ( & buf , "init.defaultBranch=%s" , branch );
866+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , branch );
861867 else {
862868 char * b = repo_default_branch_name (the_repository , 1 );
863- strbuf_addf ( & buf , "init.defaultBranch=%s" , b );
869+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , b );
864870 free (b );
865871 }
866872
867- if ((res = run_git ("-c" , buf .buf , "init" , "--" , dir , NULL )))
873+ strvec_push (& init_argv , "init" );
874+
875+ if (ref_format ) {
876+ strvec_push (& init_argv , "--ref-format" );
877+ strvec_push (& init_argv , ref_format );
878+ }
879+
880+ strvec_push (& init_argv , "--" );
881+ strvec_push (& init_argv , dir );
882+ if ((res = run_git_argv (& init_argv )))
868883 goto cleanup ;
869884
870885 if (chdir (dir ) < 0 ) {
@@ -1014,6 +1029,7 @@ static int cmd_clone(int argc, const char **argv)
10141029 free (enlistment );
10151030 free (dir );
10161031 strbuf_release (& buf );
1032+ strvec_clear (& init_argv );
10171033 free (default_cache_server_url );
10181034 free (local_cache_root_abs );
10191035 return res ;
0 commit comments