summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d574242)
raw | patch | inline | side by side (parent: d574242)
author | Jeff King <peff@peff.net> | |
Sat, 10 Dec 2011 10:31:34 +0000 (05:31 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Dec 2011 07:16:25 +0000 (23:16 -0800) |
When parsing a URL into a credential struct, we carefully
record each part of the URL, including the path on the
remote host, and use the result as part of the credential
context.
This had two practical implications:
1. Credential helpers which store a credential for later
access are likely to use the "path" portion as part of
the storage key. That means that a request to
https://example.com/foo.git
would not use the same credential that was stored in an
earlier request for:
https://example.com/bar.git
2. The prompt shown to the user includes all relevant
context, including the path.
In most cases, however, users will have a single password
per host. The behavior in (1) will be inconvenient, and the
prompt in (2) will be overly long.
This patch introduces a config option to toggle the
relevance of http paths. When turned on, we use the path as
before. When turned off, we drop the path component from the
context: helpers don't see it, and it does not appear in the
prompt.
This is nothing you couldn't do with a clever credential
helper at the start of your stack, like:
[credential "http://"]
helper = "!f() { grep -v ^path= ; }; f"
helper = your_real_helper
But doing this:
[credential]
useHttpPath = false
is way easier and more readable. Furthermore, since most
users will want the "off" behavior, that is the new default.
Users who want it "on" can set the variable (either for all
credentials, or just for a subset using
credential.*.useHttpPath).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
record each part of the URL, including the path on the
remote host, and use the result as part of the credential
context.
This had two practical implications:
1. Credential helpers which store a credential for later
access are likely to use the "path" portion as part of
the storage key. That means that a request to
https://example.com/foo.git
would not use the same credential that was stored in an
earlier request for:
https://example.com/bar.git
2. The prompt shown to the user includes all relevant
context, including the path.
In most cases, however, users will have a single password
per host. The behavior in (1) will be inconvenient, and the
prompt in (2) will be overly long.
This patch introduces a config option to toggle the
relevance of http paths. When turned on, we use the path as
before. When turned off, we drop the path component from the
context: helpers don't see it, and it does not appear in the
prompt.
This is nothing you couldn't do with a clever credential
helper at the start of your stack, like:
[credential "http://"]
helper = "!f() { grep -v ^path= ; }; f"
helper = your_real_helper
But doing this:
[credential]
useHttpPath = false
is way easier and more readable. Furthermore, since most
users will want the "off" behavior, that is the new default.
Users who want it "on" can set the variable (either for all
credentials, or just for a subset using
credential.*.useHttpPath).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
credential.c | patch | blob | history | |
credential.h | patch | blob | history | |
t/t0300-credentials.sh | patch | blob | history | |
t/t5550-http-fetch.sh | patch | blob | history |
diff --git a/credential.c b/credential.c
index 3c17ea19732c01dbd2a32bd3f3c97483ef2f5556..a17eafea582638e3d77f2e37b9d82fe5069798c0 100644 (file)
--- a/credential.c
+++ b/credential.c
if (!c->username)
c->username = xstrdup(value);
}
+ else if (!strcmp(key, "usehttppath"))
+ c->use_http_path = git_config_bool(var, value);
return 0;
}
+static int proto_is_http(const char *s)
+{
+ if (!s)
+ return 0;
+ return !strcmp(s, "https") || !strcmp(s, "http");
+}
+
static void credential_apply_config(struct credential *c)
{
if (c->configured)
return;
git_config(credential_config_callback, c);
c->configured = 1;
+
+ if (!c->use_http_path && proto_is_http(c->protocol)) {
+ free(c->path);
+ c->path = NULL;
+ }
}
static void credential_describe(struct credential *c, struct strbuf *out)
diff --git a/credential.h b/credential.h
index e5042723a87543714846961667c3bb49b2c25827..96ea41bd1c99c05d63cb965a5fc57fcd838f3fdb 100644 (file)
--- a/credential.h
+++ b/credential.h
struct credential {
struct string_list helpers;
unsigned approved:1,
- configured:1;
+ configured:1,
+ use_http_path:1;
char *username;
char *password;
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 53e94bc0382f7d2fc0fc99935269f3d630995ddf..885af8fb62a32be5d52cdf78f40b679c55cb385d 100755 (executable)
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
EOF
'
+test_expect_success 'http paths can be part of context' '
+ check fill "verbatim foo bar" <<-\EOF &&
+ protocol=https
+ host=example.com
+ path=foo.git
+ --
+ username=foo
+ password=bar
+ --
+ verbatim: get
+ verbatim: protocol=https
+ verbatim: host=example.com
+ EOF
+ test_config credential.https://example.com.useHttpPath true &&
+ check fill "verbatim foo bar" <<-\EOF
+ protocol=https
+ host=example.com
+ path=foo.git
+ --
+ username=foo
+ password=bar
+ --
+ verbatim: get
+ verbatim: protocol=https
+ verbatim: host=example.com
+ verbatim: path=foo.git
+ EOF
+'
+
test_done
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index 3262f903e14499a1d0823150713a5f81072577f9..95a133d697204a3b5dc469d188939198727e183a 100755 (executable)
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
'
expect_askpass() {
- dest=$HTTPD_DEST/auth/repo.git
+ dest=$HTTPD_DEST
{
case "$1" in
none)