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

[PATCHv2 07/13] credential: add credential.*.username

From
Jeff King <peff@peff.net>
Date
Dec 6, 2011, 06:22 UTC
Message-ID
<20111206062250.GG29233@sigill.intra.peff.net>
In-Reply-To
<20111206062127.GA29046@sigill.intra.peff.net>

Credential helpers can help users avoid having to type their username and password over and over. However, some users may not want a helper for their password, or they may be running a helper which caches for a short time. In this case, it is convenient to provide the non-secret username portion of their credential via config.

Signed-off-by: Jeff King <peff@peff.net>
---
 credential.c           |    4 ++++
 t/t0300-credentials.sh |   13 +++++++++++++
 t/t5550-http-fetch.sh  |   16 ++++++++++++++++
 3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/credential.c b/credential.c
index 96be1c2..3c17ea1 100644
--- a/credential.c
+++ b/credential.c
@@ -65,6 +65,10 @@ static int credential_config_callback(const char *var, const char *value,
 
 	if (!strcmp(key, "helper"))
 		string_list_append(&c->helpers, value);
+	else if (!strcmp(key, "username")) {
+		if (!c->username)
+			c->username = xstrdup(value);
+	}
 
 	return 0;
 }
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index e3f61f4..57751a1 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -234,4 +234,17 @@ test_expect_success 'do not match configured credential' '
 	EOF
 '
 
+test_expect_success 'pull username from config' '
+	test_config credential.https://example.com.username foo &&
+	check fill <<-\EOF
+	protocol=https
+	host=example.com
+	--
+	username=foo
+	password=askpass-password
+	--
+	askpass: Password for '\''https://foo@example.com'\'':
+	EOF
+'
+
 test_done
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index 21e2f5d..18f4d59 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -113,6 +113,22 @@ test_expect_success 'http auth respects credential helper config' '
 	expect_askpass none
 '
 
+test_expect_success 'http auth can get username from config' '
+	test_config_global "credential.$HTTPD_URL.username" user@host &&
+	>askpass-query &&
+	echo user@host >askpass-response &&
+	git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
+	expect_askpass pass user@host
+'
+
+test_expect_success 'configured username does not override URL' '
+	test_config_global "credential.$HTTPD_URL.username" wrong &&
+	>askpass-query &&
+	echo user@host >askpass-response &&
+	git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-user2 &&
+	expect_askpass pass user@host
+'
+
 test_expect_success 'fetch changes via http' '
 	echo content >>file &&
 	git commit -a -m two &&
-- 
1.7.8.rc4.4.g884ec
Previous: Jeff KingNext: Jeff King
Message 11 of 30 in “[PATCHv2 0/13] credential helpers”
  1. Jeff KingDec 6, 2011
  2. 01/13 test-lib: add test_config_global variantJeff King, Dec 6, 2011
  3. 02/13 t5550: fix typoJeff King, Dec 6, 2011
  4. 03/13 introduce credentials APIJeff King, Dec 6, 2011
  5. 04/13 credential: add function for parsing url componentsJeff King, Dec 6, 2011
  6. 05/13 http: use credential API to get passwordsJeff King, Dec 6, 2011
  7. 06/13 credential: apply helper configJeff King, Dec 6, 2011
  8. Junio C HamanoDec 6, 2011
  9. Jeff KingDec 7, 2011
  10. Jeff KingDec 7, 2011
  11. 07/13 credential: add credential.*.usernameJeff King, Dec 6, 2011
  12. 08/13 credential: make relevance of http path configurableJeff King, Dec 6, 2011
  13. 09/13 docs: end-user documentation for the credential subsystemJeff King, Dec 6, 2011
  14. 10/13 credentials: add "cache" helperJeff King, Dec 6, 2011
  15. 11/13 strbuf: add strbuf_add*_urlencodeJeff King, Dec 6, 2011
  16. 12/13 credentials: add "store" helperJeff King, Dec 6, 2011
  17. Junio C HamanoDec 6, 2011
  18. Jeff KingDec 9, 2011
  19. 13/13 t: add test harness for external credential helpersJeff King, Dec 6, 2011
  20. Junio C HamanoDec 6, 2011
  21. Jeff KingDec 6, 2011
  22. Junio C HamanoDec 6, 2011
  23. Jeff KingDec 7, 2011
  24. Junio C HamanoDec 8, 2011
  25. Jeff KingDec 9, 2011
  26. Junio C HamanoDec 9, 2011
  27. Jeff KingDec 9, 2011
  28. Junio C HamanoDec 9, 2011
  29. Jeff KingDec 9, 2011
  30. Junio C HamanoDec 9, 2011

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.