]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/partial-urlmatch-2.17'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 May 2020 21:54:29 +0000 (14:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 May 2020 21:54:29 +0000 (14:54 -0700)
Recent updates broke parsing of "credential.<url>.<key>" where
<url> is not a full URL (e.g. [credential "https://"] helper = ...)
stopped working, which has been corrected.

* js/partial-urlmatch-2.17:
  credential: handle `credential.<partial-URL>.<key>` again
  credential: optionally allow partial URLs in credential_from_url_gently()
  credential: fix grammar

1  2 
credential.c
t/t0300-credentials.sh

diff --cc credential.c
index d72e2ed0d87eb918fa6ada60d57b6753bfbc4fc5,c1a9ca4e4852bd752f70d7d6ec39388bcd709a6a..c19322d98f99a66a6dad163230fb9fd09d9e3a5e
@@@ -396,17 -395,10 +423,17 @@@ static int credential_from_url_1(struc
                        warning(_("url has no scheme: %s"), url);
                return -1;
        }
-       cp = proto_end + 3;
+       cp = proto_end ? proto_end + 3 : url;
        at = strchr(cp, '@');
        colon = strchr(cp, ':');
 -      slash = strchrnul(cp, '/');
 +
 +      /*
 +       * A query or fragment marker before the slash ends the host portion.
 +       * We'll just continue to call this "slash" for simplicity. Notably our
 +       * "trim leading slashes" part won't skip over this part of the path,
 +       * but that's what we'd want.
 +       */
 +      slash = cp + strcspn(cp, "/?#");
  
        if (!at || slash <= at) {
                /* Case (1) */
index 91a007fbfa031b97123f0cf49309ffd33d9379cd,da4b315d6dcab7fa44c665d9c8544cb9687c24c3..bc2d74098f035cde80de8282736188c6f6db3066
@@@ -620,38 -448,42 +620,76 @@@ test_expect_success 'credential system 
        test_i18ncmp expect stderr
  '
  
 +# usage: check_host_and_path <url> <expected-host> <expected-path>
 +check_host_and_path () {
 +      # we always parse the path component, but we need this to make sure it
 +      # is passed to the helper
 +      test_config credential.useHTTPPath true &&
 +      check fill "verbatim user pass" <<-EOF
 +      url=$1
 +      --
 +      protocol=https
 +      host=$2
 +      path=$3
 +      username=user
 +      password=pass
 +      --
 +      verbatim: get
 +      verbatim: protocol=https
 +      verbatim: host=$2
 +      verbatim: path=$3
 +      EOF
 +}
 +
 +test_expect_success 'url parser handles bare query marker' '
 +      check_host_and_path https://example.com?foo.git example.com ?foo.git
 +'
 +
 +test_expect_success 'url parser handles bare fragment marker' '
 +      check_host_and_path https://example.com#foo.git example.com "#foo.git"
 +'
 +
 +test_expect_success 'url parser not confused by encoded markers' '
 +      check_host_and_path https://example.com%23%3f%2f/foo.git \
 +              "example.com#?/" foo.git
 +'
 +
+ test_expect_success 'credential config with partial URLs' '
+       echo "echo password=yep" | write_script git-credential-yep &&
+       test_write_lines url=https://user@example.com/repo.git >stdin &&
+       for partial in \
+               example.com \
+               user@example.com \
+               https:// \
+               https://example.com \
+               https://example.com/ \
+               https://user@example.com \
+               https://user@example.com/ \
+               https://example.com/repo.git \
+               https://user@example.com/repo.git \
+               /repo.git
+       do
+               git -c credential.$partial.helper=yep \
+                       credential fill <stdin >stdout &&
+               grep yep stdout ||
+               return 1
+       done &&
+       for partial in \
+               dont.use.this \
+               http:// \
+               /repo
+       do
+               git -c credential.$partial.helper=yep \
+                       credential fill <stdin >stdout &&
+               ! grep yep stdout ||
+               return 1
+       done &&
+       git -c credential.$partial.helper=yep \
+               -c credential.with%0anewline.username=uh-oh \
+               credential fill <stdin >stdout 2>stderr &&
+       test_i18ngrep "skipping credential lookup for key" stderr
+ '
  test_done