@@ -153,7 +153,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email,
153
153
154
154
const char * ident_default_name (void )
155
155
{
156
- if (!git_default_name .len ) {
156
+ if (!( ident_config_given & IDENT_NAME_GIVEN ) && ! git_default_name .len ) {
157
157
copy_gecos (xgetpwuid_self (& default_name_is_bogus ), & git_default_name );
158
158
strbuf_trim (& git_default_name );
159
159
}
@@ -162,7 +162,7 @@ const char *ident_default_name(void)
162
162
163
163
const char * ident_default_email (void )
164
164
{
165
- if (!git_default_email .len ) {
165
+ if (!( ident_config_given & IDENT_MAIL_GIVEN ) && ! git_default_email .len ) {
166
166
const char * email = getenv ("EMAIL" );
167
167
168
168
if (email && email [0 ]) {
@@ -203,6 +203,15 @@ static int crud(unsigned char c)
203
203
c == '\'' ;
204
204
}
205
205
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
+
206
215
/*
207
216
* Copy over a string to the destination, but avoid special
208
217
* characters ('\n', '<' and '>') and remove crud at the end
@@ -351,44 +360,46 @@ const char *fmt_ident(const char *name, const char *email,
351
360
int want_date = !(flag & IDENT_NO_DATE );
352
361
int want_name = !(flag & IDENT_NO_NAME );
353
362
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
+
354
376
if (want_name ) {
355
377
int using_default = 0 ;
356
378
if (!name ) {
357
379
if (strict && ident_use_config_only
358
380
&& !(ident_config_given & IDENT_NAME_GIVEN )) {
359
381
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" ) );
361
383
}
362
384
name = ident_default_name ();
363
385
using_default = 1 ;
364
386
if (strict && default_name_is_bogus ) {
365
387
fputs (_ (env_hint ), stderr );
366
- die ("unable to auto-detect name (got '%s')" , name );
388
+ die (_ ( "unable to auto-detect name (got '%s')" ) , name );
367
389
}
368
390
}
369
391
if (!* name ) {
370
392
struct passwd * pw ;
371
393
if (strict ) {
372
394
if (using_default )
373
395
fputs (_ (env_hint ), stderr );
374
- die ("empty ident name (for <%s>) not allowed" , email );
396
+ die (_ ( "empty ident name (for <%s>) not allowed" ) , email );
375
397
}
376
398
pw = xgetpwuid_self (NULL );
377
399
name = pw -> pw_name ;
378
400
}
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 );
392
403
}
393
404
394
405
strbuf_reset (& ident );
@@ -403,7 +414,7 @@ const char *fmt_ident(const char *name, const char *email,
403
414
strbuf_addch (& ident , ' ' );
404
415
if (date_str && date_str [0 ]) {
405
416
if (parse_date (date_str , & ident ) < 0 )
406
- die ("invalid date format: %s" , date_str );
417
+ die (_ ( "invalid date format: %s" ) , date_str );
407
418
}
408
419
else
409
420
strbuf_addstr (& ident , ident_default_date ());
0 commit comments