static struct strbuf git_default_email = STRBUF_INIT;
static struct strbuf git_default_date = STRBUF_INIT;
static int default_email_is_bogus;
+static int default_name_is_bogus;
#define IDENT_NAME_GIVEN 01
#define IDENT_MAIL_GIVEN 02
#define get_gecos(struct_passwd) ((struct_passwd)->pw_gecos)
#endif
-static struct passwd *xgetpwuid_self(void)
+static struct passwd *xgetpwuid_self(int *is_bogus)
{
struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
- if (!pw)
- die(_("unable to look up current user in the passwd file: %s"),
- errno ? strerror(errno) : _("no such user"));
+ if (!pw) {
+ static struct passwd fallback;
+ fallback.pw_name = "unknown";
+#ifndef NO_GECOS_IN_PWENT
+ fallback.pw_gecos = "Unknown";
+#endif
+ pw = &fallback;
+ if (is_bogus)
+ *is_bogus = 1;
+ }
return pw;
}
const char *ident_default_name(void)
{
if (!git_default_name.len) {
- copy_gecos(xgetpwuid_self(), &git_default_name);
+ copy_gecos(xgetpwuid_self(&default_name_is_bogus), &git_default_name);
strbuf_trim(&git_default_name);
}
return git_default_name.buf;
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
} else
- copy_email(xgetpwuid_self(), &git_default_email,
- &default_email_is_bogus);
+ copy_email(xgetpwuid_self(&default_email_is_bogus),
+ &git_default_email, &default_email_is_bogus);
strbuf_trim(&git_default_email);
}
return git_default_email.buf;
fputs(env_hint, stderr);
die("empty ident name (for <%s>) not allowed", email);
}
- pw = xgetpwuid_self();
+ 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);