From 19a6eb42669c2d380d0bb045fe1240b1589e9ad2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 8 Feb 2019 20:34:57 +0300 Subject: Fix github-based repository fetching for URLs missing .git extension --- bpkg/fetch-git.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'bpkg/fetch-git.cxx') diff --git a/bpkg/fetch-git.cxx b/bpkg/fetch-git.cxx index d00690f..a1c420a 100644 --- a/bpkg/fetch-git.cxx +++ b/bpkg/fetch-git.cxx @@ -497,6 +497,14 @@ namespace bpkg // hanging indefinitely while trying to establish TCP/IP connection (see the // timeout_opts() function for the gory details). // + // Note that some smart HTTP(S) repositories are capable of adding missing + // .git directory extension in the URL (see git-upload-pack(1) for details). + // Some of them, specifically hosted on GitHub, do that if `git/...` value + // is specified for the User-Agent HTTP request header. We will pretend to + // be git while sensing the protocol capabilities to "fix-up" repository + // URLs, if possible. That's why the function requires the git version + // parameter. + // enum class capabilities { dumb, // No shallow clone support. @@ -505,7 +513,9 @@ namespace bpkg }; static capabilities - sense_capabilities (const common_options& co, repository_url url) + sense_capabilities (const common_options& co, + repository_url url, + const semantic_version& git_ver) { assert (url.path); @@ -531,7 +541,10 @@ namespace bpkg url.query = "service=git-upload-pack"; string u (url.string ()); - process pr (start_fetch (co, u)); + process pr (start_fetch (co, + u, + path () /* out */, + "git/" + git_ver.string ())); try { @@ -959,8 +972,11 @@ namespace bpkg auto caps = [&co, &url, &cap] () -> capabilities { + // Note that url() runs `git config --get remote.origin.url` command on + // the first call, and so git version get assigned (and checked). + // if (!cap) - cap = sense_capabilities (co, url ()); + cap = sense_capabilities (co, url (), git_ver); return *cap; }; -- cgit v1.1