Previously, before 5498c57cdd63, many people did the following: git config --global user.email "(none)" This was helpful for people with more than one E-Mail address, targeting different E-Mail addresses for different clones. as it barred git from creating commit unless the user.email config was set in the per-clone config to the correct E-Mail address. Now, since the original 'bug' was fixed, and practically every string is acceptable for user.email and user.name, it is best to reimplement the feature not as an exploit of a bug, but as an actual feature. Signed-off-by: Dan Aloni <alonid@xxxxxxxxx> --- Documentation/config.txt | 3 +++ ident.c | 5 +++++ t/t9904-per-repo-email.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100755 t/t9904-per-repo-email.sh diff --git a/Documentation/config.txt b/Documentation/config.txt index f61788668e89..f9712e7c7752 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2769,6 +2769,9 @@ user.email:: Your email address to be recorded in any newly created commits. Can be overridden by the 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_EMAIL', and 'EMAIL' environment variables. See linkgit:git-commit-tree[1]. + For people who seek setting different E-Mail addresses depending + on the clone, set to '(per-repo)' on the global configuration, + and Git will prompt you to set the E-Mail address in the clone. user.name:: Your full name to be recorded in any newly created commits. diff --git a/ident.c b/ident.c index daf7e1ea8370..0e07d45f8ff3 100644 --- a/ident.c +++ b/ident.c @@ -373,6 +373,11 @@ const char *fmt_ident(const char *name, const char *email, die("unable to auto-detect email address (got '%s')", email); } + if (strict && email && !strcmp(email, "(per-repo)")) { + die("email is '(per-repo)', suggesting to set specific email " + "for the current repo"); + } + strbuf_reset(&ident); if (want_name) { strbuf_addstr_without_crud(&ident, name); diff --git a/t/t9904-per-repo-email.sh b/t/t9904-per-repo-email.sh new file mode 100755 index 000000000000..c085ba671b85 --- /dev/null +++ b/t/t9904-per-repo-email.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# Copyright (c) 2016 Dan Aloni +# + +test_description='per-repo forced setting of E-Mail address' + +. ./test-lib.sh + +test_expect_failure 'fails commiting if clone email is not set' ' + echo "Initial" >foo && + git add foo && + unset GIT_AUTHOR_EMAIL && + git config --global user.email "(per-repo)" && + EDITOR=: VISUAL=: git commit -a -m x +' + +test_expect_success 'succeeds commiting if clone email is set' ' + echo "Initial" >foo && + git add foo && + git config --global user.email "(per-repo)" && + git config user.email "test@xxxxxx" && + EDITOR=: VISUAL=: git commit -a -m x +' + +test_done -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html