@@ -153,7 +153,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email,
153153
154154const char * ident_default_name (void )
155155{
156- if (!git_default_name .len ) {
156+ if (!( ident_config_given & IDENT_NAME_GIVEN ) && ! git_default_name .len ) {
157157 copy_gecos (xgetpwuid_self (& default_name_is_bogus ), & git_default_name );
158158 strbuf_trim (& git_default_name );
159159 }
@@ -162,7 +162,7 @@ const char *ident_default_name(void)
162162
163163const char * ident_default_email (void )
164164{
165- if (!git_default_email .len ) {
165+ if (!( ident_config_given & IDENT_MAIL_GIVEN ) && ! git_default_email .len ) {
166166 const char * email = getenv ("EMAIL" );
167167
168168 if (email && email [0 ]) {
@@ -203,6 +203,15 @@ static int crud(unsigned char c)
203203 c == '\'' ;
204204}
205205
206+ static int has_non_crud (const char * str )
207+ {
208+ for (; * str ; str ++ ) {
209+ if (!crud (* str ))
210+ return 1 ;
211+ }
212+ return 0 ;
213+ }
214+
206215/*
207216 * Copy over a string to the destination, but avoid special
208217 * characters ('\n', '<' and '>') and remove crud at the end
@@ -351,44 +360,46 @@ const char *fmt_ident(const char *name, const char *email,
351360 int want_date = !(flag & IDENT_NO_DATE );
352361 int want_name = !(flag & IDENT_NO_NAME );
353362
363+ if (!email ) {
364+ if (strict && ident_use_config_only
365+ && !(ident_config_given & IDENT_MAIL_GIVEN )) {
366+ fputs (_ (env_hint ), stderr );
367+ die (_ ("no email was given and auto-detection is disabled" ));
368+ }
369+ email = ident_default_email ();
370+ if (strict && default_email_is_bogus ) {
371+ fputs (_ (env_hint ), stderr );
372+ die (_ ("unable to auto-detect email address (got '%s')" ), email );
373+ }
374+ }
375+
354376 if (want_name ) {
355377 int using_default = 0 ;
356378 if (!name ) {
357379 if (strict && ident_use_config_only
358380 && !(ident_config_given & IDENT_NAME_GIVEN )) {
359381 fputs (_ (env_hint ), stderr );
360- die ("no name was given and auto-detection is disabled" );
382+ die (_ ( "no name was given and auto-detection is disabled" ) );
361383 }
362384 name = ident_default_name ();
363385 using_default = 1 ;
364386 if (strict && default_name_is_bogus ) {
365387 fputs (_ (env_hint ), stderr );
366- die ("unable to auto-detect name (got '%s')" , name );
388+ die (_ ( "unable to auto-detect name (got '%s')" ) , name );
367389 }
368390 }
369391 if (!* name ) {
370392 struct passwd * pw ;
371393 if (strict ) {
372394 if (using_default )
373395 fputs (_ (env_hint ), stderr );
374- die ("empty ident name (for <%s>) not allowed" , email );
396+ die (_ ( "empty ident name (for <%s>) not allowed" ) , email );
375397 }
376398 pw = xgetpwuid_self (NULL );
377399 name = pw -> pw_name ;
378400 }
379- }
380-
381- if (!email ) {
382- if (strict && ident_use_config_only
383- && !(ident_config_given & IDENT_MAIL_GIVEN )) {
384- fputs (_ (env_hint ), stderr );
385- die ("no email was given and auto-detection is disabled" );
386- }
387- email = ident_default_email ();
388- if (strict && default_email_is_bogus ) {
389- fputs (_ (env_hint ), stderr );
390- die ("unable to auto-detect email address (got '%s')" , email );
391- }
401+ if (strict && !has_non_crud (name ))
402+ die (_ ("name consists only of disallowed characters: %s" ), name );
392403 }
393404
394405 strbuf_reset (& ident );
@@ -403,7 +414,7 @@ const char *fmt_ident(const char *name, const char *email,
403414 strbuf_addch (& ident , ' ' );
404415 if (date_str && date_str [0 ]) {
405416 if (parse_date (date_str , & ident ) < 0 )
406- die ("invalid date format: %s" , date_str );
417+ die (_ ( "invalid date format: %s" ) , date_str );
407418 }
408419 else
409420 strbuf_addstr (& ident , ident_default_date ());
0 commit comments