@@ -13,11 +13,14 @@ static struct strbuf git_default_date = STRBUF_INIT;
1313static int default_email_is_bogus ;
1414static int default_name_is_bogus ;
1515
16+ static int ident_use_config_only ;
17+
1618#define IDENT_NAME_GIVEN 01
1719#define IDENT_MAIL_GIVEN 02
1820#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
1921static int committer_ident_explicitly_given ;
2022static int author_ident_explicitly_given ;
23+ static int ident_config_given ;
2124
2225#ifdef NO_GECOS_IN_PWENT
2326#define get_gecos (ignored ) "&"
@@ -345,32 +348,40 @@ const char *fmt_ident(const char *name, const char *email,
345348 int want_date = !(flag & IDENT_NO_DATE );
346349 int want_name = !(flag & IDENT_NO_NAME );
347350
348- if (want_name && !name )
349- name = ident_default_name ();
350- if (!email )
351- email = ident_default_email ();
352-
353- if (want_name && !* name ) {
354- struct passwd * pw ;
355-
356- if (strict ) {
357- if (name == git_default_name .buf )
351+ if (want_name ) {
352+ int using_default = 0 ;
353+ if (!name ) {
354+ name = ident_default_name ();
355+ using_default = 1 ;
356+ if (strict && default_name_is_bogus ) {
358357 fputs (env_hint , stderr );
359- die ("empty ident name (for <%s>) not allowed" , email );
358+ die ("unable to auto-detect name (got '%s')" , name );
359+ }
360+ if (strict && ident_use_config_only
361+ && !(ident_config_given & IDENT_NAME_GIVEN ))
362+ die ("user.useConfigOnly set but no name given" );
363+ }
364+ if (!* name ) {
365+ struct passwd * pw ;
366+ if (strict ) {
367+ if (using_default )
368+ fputs (env_hint , stderr );
369+ die ("empty ident name (for <%s>) not allowed" , email );
370+ }
371+ pw = xgetpwuid_self (NULL );
372+ name = pw -> pw_name ;
360373 }
361- pw = xgetpwuid_self (NULL );
362- name = pw -> pw_name ;
363- }
364-
365- if (want_name && strict &&
366- name == git_default_name .buf && default_name_is_bogus ) {
367- fputs (env_hint , stderr );
368- die ("unable to auto-detect name (got '%s')" , name );
369374 }
370375
371- if (strict && email == git_default_email .buf && default_email_is_bogus ) {
372- fputs (env_hint , stderr );
373- die ("unable to auto-detect email address (got '%s')" , email );
376+ if (!email ) {
377+ email = ident_default_email ();
378+ if (strict && default_email_is_bogus ) {
379+ fputs (env_hint , stderr );
380+ die ("unable to auto-detect email address (got '%s')" , email );
381+ }
382+ if (strict && ident_use_config_only
383+ && !(ident_config_given & IDENT_MAIL_GIVEN ))
384+ die ("user.useConfigOnly set but no mail given" );
374385 }
375386
376387 strbuf_reset (& ident );
@@ -444,13 +455,19 @@ int author_ident_sufficiently_given(void)
444455
445456int git_ident_config (const char * var , const char * value , void * data )
446457{
458+ if (!strcmp (var , "user.useconfigonly" )) {
459+ ident_use_config_only = git_config_bool (var , value );
460+ return 0 ;
461+ }
462+
447463 if (!strcmp (var , "user.name" )) {
448464 if (!value )
449465 return config_error_nonbool (var );
450466 strbuf_reset (& git_default_name );
451467 strbuf_addstr (& git_default_name , value );
452468 committer_ident_explicitly_given |= IDENT_NAME_GIVEN ;
453469 author_ident_explicitly_given |= IDENT_NAME_GIVEN ;
470+ ident_config_given |= IDENT_NAME_GIVEN ;
454471 return 0 ;
455472 }
456473
@@ -461,6 +478,7 @@ int git_ident_config(const char *var, const char *value, void *data)
461478 strbuf_addstr (& git_default_email , value );
462479 committer_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
463480 author_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
481+ ident_config_given |= IDENT_MAIL_GIVEN ;
464482 return 0 ;
465483 }
466484
0 commit comments