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

[RFC] ident: support per-path configs by matching the path against a pattern

From
Sebastian Schuberth <sschuberth@gmail.com>
Date
Jul 10, 2015, 09:36 UTC
Message-ID
<0000014e7752e758-a0bf7acb-2d0f-4492-8004-8eeeb9b2f042-000000@eu-west-1.amazonses.com>
Support per-path identities by configuring Git like
    $ git config user.<pattern>.email <email address>
e.g.
    $ git config user.github.email sschuberth+github@gmail.com

In this example, the middle "github" pattern is searched for case-insensitively in the absolute path name to the current git work tree. If there is a match the configured email address is used instead of what otherwise would be the default email address.

Note that repository-local identities still take precedence over global / system ones even if the pattern configured in the global / system identity matches the path to the local work tree.

This change avoids the need to use external tools like [1].
TODO: Once the community agrees that this is a feature worth having, add
tests and adjust the docs.
[1] https://github.com/prydonius/karn
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 ident.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/ident.c b/ident.c
index 5ff1aad..2429ed8 100644
--- a/ident.c
+++ b/ident.c
@@ -390,7 +390,21 @@ int author_ident_sufficiently_given(void)
 
 int git_ident_config(const char *var, const char *value, void *data)
 {
-	if (!strcmp(var, "user.name")) {
+	/* the caller has already checked that var starts with "user." */
+
+	const char *first_period = strchr(var, '.');
+	const char *last_period = strrchr(var, '.');
+
+	if (first_period < last_period) {
+		++first_period;
+		char *pattern = xstrndup(first_period, last_period - first_period);
+		const char *match = strcasestr(get_git_work_tree(), pattern);
+		free(pattern);
+		if (!match)
+			return 0;
+	}
+
+	if (ends_with(var, ".name")) {
 		if (!value)
 			return config_error_nonbool(var);
 		strbuf_reset(&git_default_name);
@@ -400,7 +414,7 @@ int git_ident_config(const char *var, const char *value, void *data)
 		return 0;
 	}
 
-	if (!strcmp(var, "user.email")) {
+	if (ends_with(var, ".email")) {
 		if (!value)
 			return config_error_nonbool(var);
 		strbuf_reset(&git_default_email);

---
https://github.com/git/git/pull/161
Next: Junio C Hamano
Message 1 of 7 in “[RFC] ident: support per-path configs by matching the path against a pattern”
  1. Sebastian SchuberthJul 10, 2015
  2. Junio C HamanoJul 10, 2015
  3. Jeff KingJul 10, 2015
  4. Jeff KingJul 10, 2015
  5. Junio C HamanoJul 10, 2015
  6. Jeff KingJul 10, 2015
  7. Junio C HamanoJul 10, 2015

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.