git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Trick to force setup of a specific configured E-Mail per repo
@ 2016-02-02 19:54 Dan Aloni
  2016-02-03  3:56 ` Jeff King
  0 siblings, 1 reply; 16+ messages in thread
From: Dan Aloni @ 2016-02-02 19:54 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-02-04  9:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-02 19:54 [PATCH] Trick to force setup of a specific configured E-Mail per repo Dan Aloni
2016-02-03  3:56 ` Jeff King
2016-02-03  5:19   ` Duy Nguyen
2016-02-03  5:22     ` Jeff King
2016-02-03  5:26       ` Duy Nguyen
2016-02-03  5:53         ` Jeff King
2016-02-03  8:01   ` Junio C Hamano
2016-02-03  8:21   ` Dan Aloni
2016-02-03 17:47     ` Eric Sunshine
2016-02-03 19:22       ` [PATCH v3] Add user.explicit boolean for when ident shouldn't be guessed Dan Aloni
2016-02-04  4:01         ` Jeff King
2016-02-04  4:19           ` Jeff King
2016-02-04  4:32             ` Jeff King
2016-02-04  5:36           ` Dan Aloni
2016-02-04  5:50             ` Jeff King
2016-02-04  9:07               ` Dan Aloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).