summaryrefslogtreecommitdiff
path: root/ident.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-02-17 18:13:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-17 18:13:31 (GMT)
commitc37f9a1bc38cad56c9eca40014802e7cd822c21c (patch)
tree9dbd9746f9cd3f6949eec3a7a10d54ac5ed047f0 /ident.c
parentdbda66b0e283494c35958316c9b1c47b6e6c9f59 (diff)
parent4d5c2956969a6690db2bbb2f3ff40459c09d7646 (diff)
downloadgit-c37f9a1bc38cad56c9eca40014802e7cd822c21c.zip
git-c37f9a1bc38cad56c9eca40014802e7cd822c21c.tar.gz
git-c37f9a1bc38cad56c9eca40014802e7cd822c21c.tar.bz2
Merge branch 'da/user-useconfigonly'
The "user.useConfigOnly" configuration variable can be used to force the user to always set user.email & user.name configuration variables, serving as a reminder for those who work on multiple projects and do not want to put these in their $HOME/.gitconfig. * da/user-useconfigonly: ident: add user.useConfigOnly boolean for when ident shouldn't be guessed fmt_ident: refactor strictness checks
Diffstat (limited to 'ident.c')
-rw-r--r--ident.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/ident.c b/ident.c
index 3da5556..6e12582 100644
--- a/ident.c
+++ b/ident.c
@@ -13,11 +13,14 @@ static struct strbuf git_default_date = STRBUF_INIT;
static int default_email_is_bogus;
static int default_name_is_bogus;
+static int ident_use_config_only;
+
#define IDENT_NAME_GIVEN 01
#define IDENT_MAIL_GIVEN 02
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
static int committer_ident_explicitly_given;
static int author_ident_explicitly_given;
+static int ident_config_given;
#ifdef NO_GECOS_IN_PWENT
#define get_gecos(ignored) "&"
@@ -345,32 +348,40 @@ const char *fmt_ident(const char *name, const char *email,
int want_date = !(flag & IDENT_NO_DATE);
int want_name = !(flag & IDENT_NO_NAME);
- if (want_name && !name)
- name = ident_default_name();
- if (!email)
- email = ident_default_email();
-
- if (want_name && !*name) {
- struct passwd *pw;
-
- if (strict) {
- if (name == git_default_name.buf)
+ if (want_name) {
+ int using_default = 0;
+ if (!name) {
+ name = ident_default_name();
+ using_default = 1;
+ if (strict && default_name_is_bogus) {
fputs(env_hint, stderr);
- die("empty ident name (for <%s>) not allowed", email);
+ die("unable to auto-detect name (got '%s')", name);
+ }
+ if (strict && ident_use_config_only
+ && !(ident_config_given & IDENT_NAME_GIVEN))
+ die("user.useConfigOnly set but no name given");
+ }
+ if (!*name) {
+ struct passwd *pw;
+ if (strict) {
+ if (using_default)
+ fputs(env_hint, stderr);
+ die("empty ident name (for <%s>) not allowed", email);
+ }
+ pw = xgetpwuid_self(NULL);
+ name = pw->pw_name;
}
- pw = xgetpwuid_self(NULL);
- name = pw->pw_name;
- }
-
- if (want_name && strict &&
- name == git_default_name.buf && default_name_is_bogus) {
- fputs(env_hint, stderr);
- die("unable to auto-detect name (got '%s')", name);
}
- if (strict && email == git_default_email.buf && default_email_is_bogus) {
- fputs(env_hint, stderr);
- die("unable to auto-detect email address (got '%s')", email);
+ if (!email) {
+ email = ident_default_email();
+ if (strict && default_email_is_bogus) {
+ fputs(env_hint, stderr);
+ die("unable to auto-detect email address (got '%s')", email);
+ }
+ if (strict && ident_use_config_only
+ && !(ident_config_given & IDENT_MAIL_GIVEN))
+ die("user.useConfigOnly set but no mail given");
}
strbuf_reset(&ident);
@@ -444,6 +455,11 @@ int author_ident_sufficiently_given(void)
int git_ident_config(const char *var, const char *value, void *data)
{
+ if (!strcmp(var, "user.useconfigonly")) {
+ ident_use_config_only = git_config_bool(var, value);
+ return 0;
+ }
+
if (!strcmp(var, "user.name")) {
if (!value)
return config_error_nonbool(var);
@@ -451,6 +467,7 @@ int git_ident_config(const char *var, const char *value, void *data)
strbuf_addstr(&git_default_name, value);
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
+ ident_config_given |= IDENT_NAME_GIVEN;
return 0;
}
@@ -461,6 +478,7 @@ int git_ident_config(const char *var, const char *value, void *data)
strbuf_addstr(&git_default_email, value);
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+ ident_config_given |= IDENT_MAIL_GIVEN;
return 0;
}