1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

Merge pull request #12801 from pascalj/2.24-maintenance

Exclude 'dir' from the FlakeRef's URL
This commit is contained in:
Jörg Thalheim 2025-05-18 23:35:53 +02:00 committed by GitHub
commit 7d15dbf9d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 3 deletions

View file

@ -234,15 +234,16 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
return std::nullopt;
}
const auto subdir = getOr(parsedURL.query, "dir", "");
parsedURL.query.erase("dir");
std::string fragment;
std::swap(fragment, parsedURL.fragment);
auto input = fetchers::Input::fromURL(fetchSettings, parsedURL, isFlake);
input.parent = baseDir;
return std::make_pair(
FlakeRef(std::move(input), getOr(parsedURL.query, "dir", "")),
fragment);
return std::make_pair(FlakeRef(std::move(input), subdir), fragment);
}
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(

View file

@ -21,4 +21,27 @@ namespace nix {
ASSERT_EQ(parsed, expected);
}
/* ----------------------------------------------------------------------------
* parseFlakeRef
* --------------------------------------------------------------------------*/
TEST(parseFlakeRef, removesDirFromInputURL) {
fetchers::Settings fetchSettings;
auto s = "git+https://localhost:8181/test/test.git?dir=subdir";
auto flakeref = parseFlakeRef(fetchSettings, s);
auto expected = "git+https://localhost:8181/test/test.git";
auto inputURL = flakeref.input.toURLString();
ASSERT_EQ(inputURL, expected);
}
TEST(parseFlakeRef, setsSubdir) {
fetchers::Settings fetchSettings;
auto s = "git+https://localhost:8181/test/test.git?dir=subdir";
auto flakeref = parseFlakeRef(fetchSettings, s);
auto expected = "subdir";
auto flakerefSubdir = flakeref.subdir;
ASSERT_EQ(flakerefSubdir, expected);
}
}