aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-11-11 17:35:58 +0000
committerJunio C Hamano <gitster@pobox.com>2007-11-22 17:05:03 -0800
commit13208572fbe8838fd8835548d7502202d1f7b21d (patch)
tree33292fe1e4b5144f3399ab630e862f8f254b2249
parent367c98866c340bc9cf5cfa88c3b69f027165fc44 (diff)
downloadgit-13208572fbe8838fd8835548d7502202d1f7b21d.tar.gz
git-13208572fbe8838fd8835548d7502202d1f7b21d.tar.xz
builtin-commit: fix --signoff
The Signed-off-by: line contained a spurious timestamp. The reason was a call to git_committer_info(1), which automatically added the timestamp. Instead, fmt_ident() was taught to interpret an empty string for the date (as opposed to NULL, which still triggers the default behavior) as "do not bother with the timestamp", and builtin-commit.c uses it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin-commit.c30
-rw-r--r--ident.c10
-rwxr-xr-xt/t7500-commit.sh12
3 files changed, 38 insertions, 14 deletions
diff --git a/builtin-commit.c b/builtin-commit.c
index 400ee93a9..780eec79b 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -183,21 +183,29 @@ static int prepare_log_message(const char *index_file, const char *prefix)
die("could not open %s\n", git_path(commit_editmsg));
stripspace(&sb, 0);
- if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
- die("could not write commit template: %s\n",
- strerror(errno));
if (signoff) {
- const char *info, *bol;
-
- info = git_committer_info(1);
- strbuf_addch(&sb, '\0');
- bol = strrchr(sb.buf + sb.len - 1, '\n');
- if (!bol || prefixcmp(bol, sign_off_header))
- fprintf(fp, "\n");
- fprintf(fp, "%s%s\n", sign_off_header, git_committer_info(1));
+ struct strbuf sob;
+ int i;
+
+ strbuf_init(&sob, 0);
+ strbuf_addstr(&sob, sign_off_header);
+ strbuf_addstr(&sob, fmt_ident(getenv("GIT_COMMITTER_NAME"),
+ getenv("GIT_COMMITTER_EMAIL"),
+ "", 1));
+ strbuf_addch(&sob, '\n');
+
+ for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
+ ; /* do nothing */
+ if (prefixcmp(sb.buf + i, sob.buf))
+ strbuf_addbuf(&sb, &sob);
+ strbuf_release(&sob);
}
+ if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
+ die("could not write commit template: %s\n",
+ strerror(errno));
+
strbuf_release(&sb);
if (in_merge && !no_edit)
diff --git a/ident.c b/ident.c
index 9b2a852cb..5be7533ff 100644
--- a/ident.c
+++ b/ident.c
@@ -224,13 +224,17 @@ const char *fmt_ident(const char *name, const char *email,
}
strcpy(date, git_default_date);
- if (date_str)
- parse_date(date_str, date, sizeof(date));
+ if (date_str) {
+ if (*date_str)
+ parse_date(date_str, date, sizeof(date));
+ else
+ date[0] = '\0';
+ }
i = copy(buffer, sizeof(buffer), 0, name);
i = add_raw(buffer, sizeof(buffer), i, " <");
i = copy(buffer, sizeof(buffer), i, email);
- i = add_raw(buffer, sizeof(buffer), i, "> ");
+ i = add_raw(buffer, sizeof(buffer), i, date[0] ? "> " : ">");
i = copy(buffer, sizeof(buffer), i, date);
if (i >= sizeof(buffer))
die("Impossibly long personal identifier");
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index cf389b81d..49c1922dd 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -122,7 +122,19 @@ test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
) &&
cmp .git/index saved-index >/dev/null
+'
+cat > expect << EOF
+zort
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+
+test_expect_success '--signoff' '
+ echo "yet another content *narf*" >> foo &&
+ echo "zort" |
+ GIT_EDITOR=../t7500/add-content git commit -s -F - foo &&
+ git cat-file commit HEAD | sed "1,/^$/d" > output &&
+ diff expect output
'
test_done