Fixed Git parsed URL scheme to align to SVN emulation of GitHub

This commit is contained in:
Matthias Koefferlein 2023-10-29 20:24:28 +01:00
parent e83b3c1477
commit 3e34d205e8
3 changed files with 12 additions and 14 deletions

View File

@ -101,24 +101,22 @@ parse_git_url (tl::Extractor &ex, std::string &url, std::string &branch, std::st
// SVN emulation // SVN emulation
auto parts = tl::split (subfolder, "/"); auto parts = tl::split (subfolder, "/");
if (parts.size () >= 1 && parts.back () == "trunk") { if (parts.size () >= 1 && parts.front () == "trunk") {
branch = "HEAD"; branch = "HEAD";
parts.pop_back (); parts.erase (parts.begin ());
subfolder = tl::join (parts, "/"); subfolder = tl::join (parts, "/");
} else if (parts.size () >= 2 && parts[parts.size () - 2] == "tags") { } else if (parts.size () >= 2 && parts.front () == "tags") {
branch = "refs/tags/" + parts.back (); branch = "refs/tags/" + parts[1];
parts.pop_back (); parts.erase (parts.begin (), parts.begin () + 2);
parts.pop_back ();
subfolder = tl::join (parts, "/"); subfolder = tl::join (parts, "/");
} else if (parts.size () >= 2 && parts[parts.size () - 2] == "branches") { } else if (parts.size () >= 2 && parts.front () == "branches") {
branch = "refs/heads/" + parts.back (); branch = "refs/heads/" + parts[1];
parts.pop_back (); parts.erase (parts.begin (), parts.begin () + 2);
parts.pop_back ();
subfolder = tl::join (parts, "/"); subfolder = tl::join (parts, "/");
} }

View File

@ -55,10 +55,10 @@ enum Protocol {
* git+https://server.com/repo.git[v1.0] -> protocol=Git, url="https://server.com/repo.git", branch="v1.0", subfolder="" * git+https://server.com/repo.git[v1.0] -> protocol=Git, url="https://server.com/repo.git", branch="v1.0", subfolder=""
* git+https://server.com/repo.git/sub/folder[refs/tags/1.0] -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.0", subfolder="sub/folder" * git+https://server.com/repo.git/sub/folder[refs/tags/1.0] -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.0", subfolder="sub/folder"
* git+https://server.com/repo.git/trunk -> protocol=Git, url="https://server.com/repo.git", branch="HEAD", subfolder="" * git+https://server.com/repo.git/trunk -> protocol=Git, url="https://server.com/repo.git", branch="HEAD", subfolder=""
* git+https://server.com/repo.git/sub/folder/trunk -> protocol=Git, url="https://server.com/repo.git", branch="HEAD", subfolder="sub/folder" * git+https://server.com/repo.git/trunk/sub/folder -> protocol=Git, url="https://server.com/repo.git", branch="HEAD", subfolder="sub/folder"
* git+https://server.com/repo.git/branches/release -> protocol=Git, url="https://server.com/repo.git", branch="refs/heads/release", subfolder="" * git+https://server.com/repo.git/branches/release -> protocol=Git, url="https://server.com/repo.git", branch="refs/heads/release", subfolder=""
* git+https://server.com/repo.git/tags/1.9 -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.9", subfolder="" * git+https://server.com/repo.git/tags/1.9 -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.9", subfolder=""
* git+https://server.com/repo.git/sub/folder/tags/1.9 -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.9", subfolder="sub/folder" * git+https://server.com/repo.git/tags/1.9/sub/folder -> protocol=Git, url="https://server.com/repo.git", branch="refs/tags/1.9", subfolder="sub/folder"
*/ */
class LAY_PUBLIC SaltParsedURL class LAY_PUBLIC SaltParsedURL

View File

@ -97,7 +97,7 @@ TEST (15_GitSVNEmulationTrunk)
TEST (16_GitSVNEmulationTrunkWithSubFolder) TEST (16_GitSVNEmulationTrunkWithSubFolder)
{ {
lay::SaltParsedURL purl ("git+https://server.com/repo.git/sub/folder/trunk"); lay::SaltParsedURL purl ("git+https://server.com/repo.git/trunk/sub/folder");
EXPECT_EQ (purl.protocol () == lay::Git, true); EXPECT_EQ (purl.protocol () == lay::Git, true);
EXPECT_EQ (purl.url (), "https://server.com/repo.git"); EXPECT_EQ (purl.url (), "https://server.com/repo.git");
EXPECT_EQ (purl.branch (), "HEAD"); EXPECT_EQ (purl.branch (), "HEAD");
@ -124,7 +124,7 @@ TEST (18_GitSVNEmulationTag)
TEST (19_GitSVNEmulationTagWithSubFolder) TEST (19_GitSVNEmulationTagWithSubFolder)
{ {
lay::SaltParsedURL purl ("git+https://server.com/repo.git/sub/folder/tags/1.9"); lay::SaltParsedURL purl ("git+https://server.com/repo.git/tags/1.9/sub/folder");
EXPECT_EQ (purl.protocol () == lay::Git, true); EXPECT_EQ (purl.protocol () == lay::Git, true);
EXPECT_EQ (purl.url (), "https://server.com/repo.git"); EXPECT_EQ (purl.url (), "https://server.com/repo.git");
EXPECT_EQ (purl.branch (), "refs/tags/1.9"); EXPECT_EQ (purl.branch (), "refs/tags/1.9");