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

Handle env vars in a case-preserving, case-insensitive manner on Windows #574

Merged
merged 14 commits into from
Oct 21, 2024

Conversation

niik
Copy link
Member

@niik niik commented Jun 5, 2024

This is a follow-up to #570 and attempts to tackle Windows environment variable shenanigans for all environment variables and not just PATH. The main change is the introduction of EnvMap, a class that behaves as a case-insensitive, case-preserving map on Windows and a regular case-sensitive map on other platforms. This class is used in lib/git-environment.ts to handle environment variables in a consistent manner across platforms.

I've also bumped Prettier to 3.3.1 so it can handle my syntax and specified the version of TypeScript used by Visual Studio Code in .vscode/settings.json because I was building this on an old VM with an old VS code and noticed that it wouldn't complete properly.

@niik niik requested review from sergiou87 and tidy-dev June 5, 2024 12:12
@tidy-dev
Copy link
Contributor

tidy-dev commented Jun 6, 2024

@niik Just making sure you were aware of the failing tests (I have been putting off reviewing till those are happy)

@niik
Copy link
Member Author

niik commented Jun 7, 2024

Just making sure you were aware of the failing tests (I have been putting off reviewing till those are happy)

I was not aware, thanks for the heads up!

Copy link
Member

@sergiou87 sergiou87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks all good! Just have a question about one of the tests, not sure if it's 100% useful the way it is right now 🤔

@@ -53,11 +53,20 @@ describe('environment variables', () => {
// case-insensitive (like Windows) we don't end up with an invalid PATH
// and the original one lost in the process.
const { env } = setupEnvironment({})
expect(env.PATH).toContain('wow-such-case-insensitivity')
expect(env.Path).toContain('wow-such-case-insensitivity')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be checking PATH to prove it's case insensitive? 🤔 Or both…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy, this was 5 months ago but I think this is correct albeit highly confusing. It's meant to test that on Windows the env map is case preserving but case insensitive. That said I tried to update the test to be more clear and found a bug in EnvMap's constructor. Happy for you to take another look now!

@niik niik merged commit b4d51b8 into main Oct 21, 2024
9 checks passed
@niik niik deleted the env-map branch October 21, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants