git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Trick to force setup of a specific configured E-Mail per repo

From
Dan Aloni <alonid@gmail.com>
Date
Feb 2, 2016, 19:54 UTC
Message-ID
<1454442861-4879-1-git-send-email-alonid@gmail.com>
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@gmail.com>
---
 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@ok.com" &&
+	EDITOR=: VISUAL=: git commit -a -m x
+'
+
+test_done
-- 
2.5.0
Next: Jeff King
Message 1 of 16 in “Trick to force setup of a specific configured E-Mail per repo”
  1. Trick to force setup of a specific configured E-Mail per repoDan Aloni, Feb 2, 2016
  2. Jeff KingFeb 3, 2016
  3. Duy NguyenFeb 3, 2016
  4. Jeff KingFeb 3, 2016
  5. Duy NguyenFeb 3, 2016
  6. Jeff KingFeb 3, 2016
  7. Junio C HamanoFeb 3, 2016
  8. Dan AloniFeb 3, 2016
  9. Eric SunshineFeb 3, 2016
  10. Add user.explicit boolean for when ident shouldn't be guessedDan Aloni, Feb 3, 2016
  11. Jeff KingFeb 4, 2016
  12. Jeff KingFeb 4, 2016
  13. Jeff KingFeb 4, 2016
  14. Dan AloniFeb 4, 2016
  15. Jeff KingFeb 4, 2016
  16. Dan AloniFeb 4, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.