@@ -2999,7 +2999,7 @@ struct add_data {
29992999};
30003000#define ADD_DATA_INIT { .depth = -1 }
30013001
3002- static void show_fetch_remotes ( FILE * output , const char * git_dir_path )
3002+ static void append_fetch_remotes ( struct strbuf * msg , const char * git_dir_path )
30033003{
30043004 struct child_process cp_remote = CHILD_PROCESS_INIT ;
30053005 struct strbuf sb_remote_out = STRBUF_INIT ;
@@ -3015,7 +3015,7 @@ static void show_fetch_remotes(FILE *output, const char *git_dir_path)
30153015 while ((next_line = strchr (line , '\n' )) != NULL ) {
30163016 size_t len = next_line - line ;
30173017 if (strip_suffix_mem (line , & len , " (fetch)" ))
3018- fprintf ( output , " %.*s\n" , (int )len , line );
3018+ strbuf_addf ( msg , " %.*s\n" , (int )len , line );
30193019 line = next_line + 1 ;
30203020 }
30213021 }
@@ -3047,19 +3047,27 @@ static int add_submodule(const struct add_data *add_data)
30473047
30483048 if (is_directory (submod_gitdir_path )) {
30493049 if (!add_data -> force ) {
3050- fprintf (stderr , _ ("A git directory for '%s' is found "
3051- "locally with remote(s):" ),
3052- add_data -> sm_name );
3053- show_fetch_remotes (stderr , submod_gitdir_path );
3050+ struct strbuf msg = STRBUF_INIT ;
3051+ char * die_msg ;
3052+
3053+ strbuf_addf (& msg , _ ("A git directory for '%s' is found "
3054+ "locally with remote(s):\n" ),
3055+ add_data -> sm_name );
3056+
3057+ append_fetch_remotes (& msg , submod_gitdir_path );
30543058 free (submod_gitdir_path );
3055- die (_ ("If you want to reuse this local git "
3056- "directory instead of cloning again from\n"
3057- " %s\n"
3058- "use the '--force' option. If the local git "
3059- "directory is not the correct repo\n"
3060- "or if you are unsure what this means, choose "
3061- "another name with the '--name' option.\n" ),
3062- add_data -> realrepo );
3059+
3060+ strbuf_addf (& msg , _ ("If you want to reuse this local git "
3061+ "directory instead of cloning again from\n"
3062+ " %s\n"
3063+ "use the '--force' option. If the local git "
3064+ "directory is not the correct repo\n"
3065+ "or you are unsure what this means choose "
3066+ "another name with the '--name' option." ),
3067+ add_data -> realrepo );
3068+
3069+ die_msg = strbuf_detach (& msg , NULL );
3070+ die ("%s" , die_msg );
30633071 } else {
30643072 printf (_ ("Reactivating local git directory for "
30653073 "submodule '%s'\n" ), add_data -> sm_name );
0 commit comments