mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
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>
This commit is contained in:
parent
e83dbe802f
commit
bb1ae3f6ff
|
@ -446,6 +446,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
|
|||
FILE *fp;
|
||||
const char *hook_arg1 = NULL;
|
||||
const char *hook_arg2 = NULL;
|
||||
int ident_shown = 0;
|
||||
|
||||
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
|
||||
return 0;
|
||||
|
@ -527,6 +528,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
|
|||
|
||||
determine_author_info();
|
||||
|
||||
/* This checks if committer ident is explicitly given */
|
||||
git_committer_info(0);
|
||||
if (use_editor) {
|
||||
char *author_ident;
|
||||
const char *committer_ident;
|
||||
|
@ -558,12 +561,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
|
|||
getenv("GIT_COMMITTER_EMAIL"));
|
||||
if (strcmp(author_ident, committer_ident))
|
||||
fprintf(fp,
|
||||
"#\n"
|
||||
"# Author: %s\n"
|
||||
"#\n",
|
||||
"%s"
|
||||
"# Author: %s\n",
|
||||
ident_shown++ ? "" : "#\n",
|
||||
author_ident);
|
||||
free(author_ident);
|
||||
|
||||
if (!user_ident_explicitly_given)
|
||||
fprintf(fp,
|
||||
"%s"
|
||||
"# Committer: %s\n",
|
||||
ident_shown++ ? "" : "#\n",
|
||||
committer_ident);
|
||||
|
||||
if (ident_shown)
|
||||
fprintf(fp, "#\n");
|
||||
|
||||
saved_color_setting = wt_status_use_color;
|
||||
wt_status_use_color = 0;
|
||||
commitable = run_status(fp, index_file, prefix, 1);
|
||||
|
|
1
cache.h
1
cache.h
|
@ -719,6 +719,7 @@ extern int config_error_nonbool(const char *);
|
|||
#define MAX_GITNAME (1000)
|
||||
extern char git_default_email[MAX_GITNAME];
|
||||
extern char git_default_name[MAX_GITNAME];
|
||||
extern int user_ident_explicitly_given;
|
||||
|
||||
extern const char *git_commit_encoding;
|
||||
extern const char *git_log_output_encoding;
|
||||
|
|
4
config.c
4
config.c
|
@ -443,6 +443,8 @@ int git_default_config(const char *var, const char *value)
|
|||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
strlcpy(git_default_name, value, sizeof(git_default_name));
|
||||
if (git_default_email[0])
|
||||
user_ident_explicitly_given = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -450,6 +452,8 @@ int git_default_config(const char *var, const char *value)
|
|||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
strlcpy(git_default_email, value, sizeof(git_default_email));
|
||||
if (git_default_name[0])
|
||||
user_ident_explicitly_given = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
char git_default_email[MAX_GITNAME];
|
||||
char git_default_name[MAX_GITNAME];
|
||||
int user_ident_explicitly_given;
|
||||
int trust_executable_bit = 1;
|
||||
int quote_path_fully = 1;
|
||||
int has_symlinks = 1;
|
||||
|
|
3
ident.c
3
ident.c
|
@ -250,6 +250,9 @@ const char *git_author_info(int flag)
|
|||
|
||||
const char *git_committer_info(int flag)
|
||||
{
|
||||
if (getenv("GIT_COMMITTER_NAME") &&
|
||||
getenv("GIT_COMMITTER_EMAIL"))
|
||||
user_ident_explicitly_given = 1;
|
||||
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
|
||||
getenv("GIT_COMMITTER_EMAIL"),
|
||||
getenv("GIT_COMMITTER_DATE"),
|
||||
|
|
|
@ -166,6 +166,21 @@ test_expect_success 'author different from committer' '
|
|||
test_cmp expect actual
|
||||
'
|
||||
|
||||
sed -i '$d' expect
|
||||
echo "# Committer:
|
||||
#" >> expect
|
||||
unset GIT_COMMITTER_EMAIL
|
||||
unset GIT_COMMITTER_NAME
|
||||
|
||||
test_expect_success 'committer is automatic' '
|
||||
|
||||
echo >>negative &&
|
||||
git commit -e -m "sample"
|
||||
head -n 8 .git/COMMIT_EDITMSG | \
|
||||
sed "s/^# Committer: .*/# Committer:/" >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
pwd=`pwd`
|
||||
cat >> .git/FAKE_EDITOR << EOF
|
||||
#! /bin/sh
|
||||
|
|
Loading…
Reference in a new issue