From: "Santi Béjar" <sbejar@gmail.com>
To: git@vger.kernel.org
Cc: "Santi Béjar" <sbejar@gmail.com>
Subject: [PATCHv4 3/4] commit: Show committer if automatic
Date: Sun, 4 May 2008 18:04:51 +0200 [thread overview]
Message-ID: <1209917092-12146-4-git-send-email-sbejar@gmail.com> (raw)
In-Reply-To: <1209917092-12146-1-git-send-email-sbejar@gmail.com>
To warn the user in case he/she might be using an unintended
committer identity.
Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
builtin-commit.c | 19 ++++++++++++++++---
cache.h | 1 +
config.c | 4 ++++
environment.c | 1 +
ident.c | 3 +++
t/t7502-commit.sh | 15 +++++++++++++++
6 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index d03b6b2..353f9c7 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -448,6 +448,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
const char *hook_arg2 = NULL;
const char *author_ident;
const char *committer_ident;
+ int showed_ident = 0;
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
return 0;
@@ -528,6 +529,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
strbuf_release(&sb);
determine_author_info();
+ /* To know if the committer ident is automatic */
+ git_committer_info(0);
if (use_editor) {
if (in_merge)
@@ -558,11 +561,21 @@ 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",
+ showed_ident++ ? "" : "#\n",
author_ident);
+ if (!user_explicit)
+ fprintf(fp,
+ "%s"
+ "# Committer: %s\n",
+ showed_ident++ ? "" : "#\n",
+ committer_ident);
+
+ if (showed_ident)
+ fprintf(fp, "#\n");
+
saved_color_setting = wt_status_use_color;
wt_status_use_color = 0;
commitable = run_status(fp, index_file, prefix, 1);
diff --git a/cache.h b/cache.h
index 5a28ddd..e8b26cf 100644
--- a/cache.h
+++ b/cache.h
@@ -718,6 +718,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_explicit;
extern const char *git_commit_encoding;
extern const char *git_log_output_encoding;
diff --git a/config.c b/config.c
index b0ada51..e49804a 100644
--- a/config.c
+++ b/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_explicit = 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_explicit = 1;
return 0;
}
diff --git a/environment.c b/environment.c
index 6739a3f..b941971 100644
--- a/environment.c
+++ b/environment.c
@@ -11,6 +11,7 @@
char git_default_email[MAX_GITNAME];
char git_default_name[MAX_GITNAME];
+int user_explicit = 0;
int trust_executable_bit = 1;
int quote_path_fully = 1;
int has_symlinks = 1;
diff --git a/ident.c b/ident.c
index ed44a53..67ccbf3 100644
--- a/ident.c
+++ b/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_explicit = 1;
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
getenv("GIT_COMMITTER_DATE"),
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 0b1db40..018060c 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -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
--
1.5.5.1.224.gadb29
next prev parent reply other threads:[~2008-05-04 16:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-04 16:04 [PATCHv4 0/4] Show author and/or committer in some cases Santi Béjar
2008-05-04 16:04 ` [PATCHv4 1/4] Preparation to call determine_author_info from prepare_to_commit Santi Béjar
2008-05-04 16:12 ` Santi Béjar
2008-05-04 16:04 ` [PATCHv4 2/4] commit: Show author if different from committer Santi Béjar
2008-05-06 23:34 ` Junio C Hamano
2008-05-04 16:04 ` Santi Béjar [this message]
2008-05-04 16:04 ` [PATCHv4 4/4] user.warnautomatic: add config to control if the committer ident is shown Santi Béjar
2008-05-07 16:12 ` Junio C Hamano
2008-05-07 16:32 ` Santi Béjar
2008-05-04 16:25 ` [PATCHv4 0/4] Show author and/or committer in some cases Santi Béjar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1209917092-12146-4-git-send-email-sbejar@gmail.com \
--to=sbejar@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.