commit: Show committer if automatic
To warn the user in case he/she might be using an unintended committer identity. Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Santi Béjar committed
May 4, 2008 at 18:04 UTC
bb1ae3f6fff19b0a1ab1bb6a815d26d39b9f15e6
6 files changed
+40
-3
builtin-commit.c
+16
-3
@@ -446,6 +446,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
446
FILE *fp;
447
const char *hook_arg1 = NULL;
448
const char *hook_arg2 = NULL;
449
+ int ident_shown = 0;
450
451
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
452
return 0;
@@ -527,6 +528,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
528
529
determine_author_info();
530
531
+ /* This checks if committer ident is explicitly given */
532
+ git_committer_info(0);
533
if (use_editor) {
534
char *author_ident;
535
const char *committer_ident;
@@ -558,12 +561,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
561
getenv("GIT_COMMITTER_EMAIL"));
562
if (strcmp(author_ident, committer_ident))
563
fprintf(fp,
561
- "#\n"
562
- "# Author: %s\n"
563
- "#\n",
564
+ "%s"
565
+ "# Author: %s\n",
566
+ ident_shown++ ? "" : "#\n",
567
author_ident);
568
free(author_ident);
569
570
+ if (!user_ident_explicitly_given)
571
+ fprintf(fp,
572
+ "%s"
573
+ "# Committer: %s\n",
574
+ ident_shown++ ? "" : "#\n",
575
+ committer_ident);
576
+
577
+ if (ident_shown)
578
+ fprintf(fp, "#\n");
579
+
580
saved_color_setting = wt_status_use_color;
581
wt_status_use_color = 0;
582
commitable = run_status(fp, index_file, prefix, 1);
cache.h
+1
@@ -719,6 +719,7 @@ extern int config_error_nonbool(const char *);
719
#define MAX_GITNAME (1000)
720
extern char git_default_email[MAX_GITNAME];
721
extern char git_default_name[MAX_GITNAME];
722
+extern int user_ident_explicitly_given;
723
724
extern const char *git_commit_encoding;
725
extern const char *git_log_output_encoding;
config.c
+4
@@ -443,6 +443,8 @@ int git_default_config(const char *var, const char *value)
443
if (!value)
444
return config_error_nonbool(var);
445
strlcpy(git_default_name, value, sizeof(git_default_name));
446
+ if (git_default_email[0])
447
+ user_ident_explicitly_given = 1;
448
return 0;
449
}
450
@@ -450,6 +452,8 @@ int git_default_config(const char *var, const char *value)
452
if (!value)
453
return config_error_nonbool(var);
454
strlcpy(git_default_email, value, sizeof(git_default_email));
455
+ if (git_default_name[0])
456
+ user_ident_explicitly_given = 1;
457
return 0;
458
}
459
environment.c
+1
@@ -11,6 +11,7 @@
11
12
char git_default_email[MAX_GITNAME];
13
char git_default_name[MAX_GITNAME];
14
+int user_ident_explicitly_given;
15
int trust_executable_bit = 1;
16
int quote_path_fully = 1;
17
int has_symlinks = 1;
ident.c
+3
@@ -250,6 +250,9 @@ const char *git_author_info(int flag)
250
251
const char *git_committer_info(int flag)
252
{
253
+ if (getenv("GIT_COMMITTER_NAME") &&
254
+ getenv("GIT_COMMITTER_EMAIL"))
255
+ user_ident_explicitly_given = 1;
256
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
257
getenv("GIT_COMMITTER_EMAIL"),
258
getenv("GIT_COMMITTER_DATE"),
t/t7502-commit.sh
+15
@@ -166,6 +166,21 @@ test_expect_success 'author different from committer' '
166
test_cmp expect actual
167
'
168
169
+sed -i '$d' expect
170
+echo "# Committer:
171
+#" >> expect
172
+unset GIT_COMMITTER_EMAIL
173
+unset GIT_COMMITTER_NAME
174
+
175
+test_expect_success 'committer is automatic' '
176
+
177
+ echo >>negative &&
178
+ git commit -e -m "sample"
179
+ head -n 8 .git/COMMIT_EDITMSG | \
180
+ sed "s/^# Committer: .*/# Committer:/" >actual &&
181
+ test_cmp expect actual
182
+'
183
+
184
pwd=`pwd`
185
cat >> .git/FAKE_EDITOR << EOF
186
#! /bin/sh