Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude 'dir' from the FlakeRef's URL #12801

Draft
wants to merge 1 commit into
base: 2.24-maintenance
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/libflake/flake/flakeref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/libflake/flakeref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}