Isolating test from accessing global git credential helper config#16895
Merged
Conversation
samypr100
reviewed
Nov 30, 2025
Comment on lines
+568
to
+580
| pub fn with_git_credential_helper_blocked(self) -> Self { | ||
| let path = self.home_dir.join(".gitconfig"); | ||
| let mut file = fs_err::OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open(&path) | ||
| .expect("Failed to open gitconfig file"); | ||
|
|
||
| writeln!(file, "[credential]\n\thelper =\n") | ||
| .expect("Failed to write credential helper to gitconfig"); | ||
|
|
||
| self | ||
| } |
Collaborator
There was a problem hiding this comment.
We may be able to leverage the existing assert_fs support, e.g.
Suggested change
| pub fn with_git_credential_helper_blocked(self) -> Self { | |
| let path = self.home_dir.join(".gitconfig"); | |
| let mut file = fs_err::OpenOptions::new() | |
| .create(true) | |
| .append(true) | |
| .open(&path) | |
| .expect("Failed to open gitconfig file"); | |
| writeln!(file, "[credential]\n\thelper =\n") | |
| .expect("Failed to write credential helper to gitconfig"); | |
| self | |
| } | |
| pub fn with_unset_git_credential_helper(self) -> Self { | |
| let git_config = self.home_dir.child(".gitconfig"); | |
| git_config | |
| .write_str(indoc! {r" | |
| [credential] | |
| helper = | |
| "}) | |
| .expect("Failed to unset git credential helper"); | |
| self | |
| } |
Contributor
Author
There was a problem hiding this comment.
Yup that works. Made the change
CodSpeed Performance ReportMerging #16895 will degrade performances by 22.34%Comparing Summary
Benchmarks breakdown
|
konstin
approved these changes
Dec 1, 2025
konstin
left a comment
Member
There was a problem hiding this comment.
I tested this both on Windows and Linux.
Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves: #1980
Added a utility function to TestContext called with_git_credential_helper_blocked that isolates the test from accessing the credential helper value defined in global/system git config. It does so, by writing to a file .gitconfig in the temporary home_dir that is created as part of the TestContext.
Test Plan
Tested it by running the test pip_install::install_git_private_https_pat_and_username, and making sure it doesn't affect the keyring.
Note:
The commit hash for the uv-private-package seems to have changed. Kindly, ensure that the modification related to that is correct.