Skip to content

Commit 6ead397

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/ident'
* jc/ident: Keep Porcelainish from failing by broken ident after making changes. Delay "empty ident" errors until they really matter. Make "empty ident" error message a bit more helpful.
2 parents 0f73e92 + e3b59a4 commit 6ead397

File tree

8 files changed

+45
-16
lines changed

8 files changed

+45
-16
lines changed

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ void datestamp(char *buf, int bufsize);
246246
unsigned long approxidate(const char *);
247247

248248
extern int setup_ident(void);
249-
extern const char *git_author_info(void);
250-
extern const char *git_committer_info(void);
249+
extern const char *git_author_info(int);
250+
extern const char *git_committer_info(int);
251251

252252
struct checkout {
253253
const char *base_dir;

commit-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ int main(int argc, char **argv)
118118
add_buffer(&buffer, &size, "parent %s\n", sha1_to_hex(parent_sha1[i]));
119119

120120
/* Person/date information */
121-
add_buffer(&buffer, &size, "author %s\n", git_author_info());
122-
add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info());
121+
add_buffer(&buffer, &size, "author %s\n", git_author_info(1));
122+
add_buffer(&buffer, &size, "committer %s\n\n", git_committer_info(1));
123123

124124
/* And add the comment */
125125
while (fgets(comment, sizeof(comment), stdin) != NULL)

git-am.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/sh
22
#
3-
#
3+
# Copyright (c) 2005, 2006 Junio C Hamano
44

55
USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>
66
or, when resuming [--skip | --resolved]'
77
. git-sh-setup
88

9+
git var GIT_COMMITTER_IDENT >/dev/null || exit
10+
911
stop_here () {
1012
echo "$1" >"$dotest/next"
1113
exit 1

git-applymbox.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
2222
. git-sh-setup
2323

24+
git var GIT_COMMITTER_IDENT >/dev/null || exit
25+
2426
keep_subject= query_apply= continue= utf8= resume=t
2527
while case "$#" in 0) break ;; esac
2628
do

git-merge.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ case "$#,$common,$no_commit" in
142142
1,*,)
143143
# We are not doing octopus, not fast forward, and have only
144144
# one common. See if it is really trivial.
145+
git var GIT_COMMITTER_IDENT >/dev/null || exit
146+
145147
echo "Trying really trivial in-index merge..."
146148
git-update-index --refresh 2>/dev/null
147149
if git-read-tree --trivial -m -u $common $head "$1" &&
@@ -179,6 +181,9 @@ case "$#,$common,$no_commit" in
179181
;;
180182
esac
181183

184+
# We are going to make a new commit.
185+
git var GIT_COMMITTER_IDENT >/dev/null || exit
186+
182187
case "$use_strategies" in
183188
'')
184189
case "$#" in

git-resolve.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ case "$common" in
5050
;;
5151
esac
5252

53+
# We are going to make a new commit.
54+
git var GIT_COMMITTER_IDENT >/dev/null || exit
55+
5356
# Find an optimum merge base if there are more than one candidates.
5457
LF='
5558
'

ident.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,18 @@ static int copy(char *buf, int size, int offset, const char *src)
156156
return offset;
157157
}
158158

159+
static const char au_env[] = "GIT_AUTHOR_NAME";
160+
static const char co_env[] = "GIT_COMMITTER_NAME";
161+
static const char *env_hint =
162+
"\n*** Environment problem:\n"
163+
"*** Your name cannot be determined from your system services (gecos).\n"
164+
"*** You would need to set %s and %s\n"
165+
"*** environment variables; otherwise you won't be able to perform\n"
166+
"*** certain operations because of \"empty ident\" errors.\n"
167+
"*** Alternatively, you can use user.name configuration variable.\n\n";
168+
159169
static const char *get_ident(const char *name, const char *email,
160-
const char *date_str)
170+
const char *date_str, int error_on_no_name)
161171
{
162172
static char buffer[1000];
163173
char date[50];
@@ -168,9 +178,14 @@ static const char *get_ident(const char *name, const char *email,
168178
if (!email)
169179
email = git_default_email;
170180

171-
if (!*name || !*email)
172-
die("empty ident %s <%s> not allowed",
173-
name, email);
181+
if (!*name) {
182+
if (name == git_default_name && env_hint) {
183+
fprintf(stderr, env_hint, au_env, co_env);
184+
env_hint = NULL; /* warn only once, for "git-var -l" */
185+
}
186+
if (error_on_no_name)
187+
die("empty ident %s <%s> not allowed", name, email);
188+
}
174189

175190
strcpy(date, git_default_date);
176191
if (date_str)
@@ -187,16 +202,18 @@ static const char *get_ident(const char *name, const char *email,
187202
return buffer;
188203
}
189204

190-
const char *git_author_info(void)
205+
const char *git_author_info(int error_on_no_name)
191206
{
192207
return get_ident(getenv("GIT_AUTHOR_NAME"),
193208
getenv("GIT_AUTHOR_EMAIL"),
194-
getenv("GIT_AUTHOR_DATE"));
209+
getenv("GIT_AUTHOR_DATE"),
210+
error_on_no_name);
195211
}
196212

197-
const char *git_committer_info(void)
213+
const char *git_committer_info(int error_on_no_name)
198214
{
199215
return get_ident(getenv("GIT_COMMITTER_NAME"),
200216
getenv("GIT_COMMITTER_EMAIL"),
201-
getenv("GIT_COMMITTER_DATE"));
217+
getenv("GIT_COMMITTER_DATE"),
218+
error_on_no_name);
202219
}

var.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static const char var_usage[] = "git-var [-l | <variable>]";
1212

1313
struct git_var {
1414
const char *name;
15-
const char *(*read)(void);
15+
const char *(*read)(int);
1616
};
1717
static struct git_var git_vars[] = {
1818
{ "GIT_COMMITTER_IDENT", git_committer_info },
@@ -24,7 +24,7 @@ static void list_vars(void)
2424
{
2525
struct git_var *ptr;
2626
for(ptr = git_vars; ptr->read; ptr++) {
27-
printf("%s=%s\n", ptr->name, ptr->read());
27+
printf("%s=%s\n", ptr->name, ptr->read(0));
2828
}
2929
}
3030

@@ -35,7 +35,7 @@ static const char *read_var(const char *var)
3535
val = NULL;
3636
for(ptr = git_vars; ptr->read; ptr++) {
3737
if (strcmp(var, ptr->name) == 0) {
38-
val = ptr->read();
38+
val = ptr->read(1);
3939
break;
4040
}
4141
}

0 commit comments

Comments
 (0)