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

Use get_entry instead of get_str #269

Merged
merged 1 commit into from Feb 4, 2021

Conversation

cruessler
Copy link
Contributor

Related to #79 and #228.

Beware that the additional tests most likely will fail locally because the local git config interferes with them. This PR is intended for testing whether there are issues on CI.

@extrawurst
Copy link
Owner

Beware that the additional tests most likely will fail locally

how are you planning to work around this?

This PR is intended for testing whether there are issues on CI.

looks good doesn't it?

@cruessler
Copy link
Contributor Author

Beware that the additional tests most likely will fail locally

how are you planning to work around this?

I don’t have a solution yet, so I’ll do a little research to see what other projects are doing.

This PR is intended for testing whether there are issues on CI.

looks good doesn't it?

Yes, the git config used on CI seems to not interfere with the new tests.

@cruessler
Copy link
Contributor Author

cruessler commented Sep 6, 2020

@extrawurst I might have found a solution. Setting $HOME to an empty directory in repo_init_empty prevents git from falling back to $HOME/.gitconfig because that is now guaranteed to be empty. git itself does not provide more granular env variables as far as I could tell. I’m not 100 % sure whether undesired side-effects can occur if we just change $HOME in the middle of a test, though.

@extrawurst
Copy link
Owner

Sorry for the delay, this would break tests that depend on $HOME to be something useful, right? and since we run tests in parallel it would be non-deterministic.

@cruessler
Copy link
Contributor Author

I did a little research to see how other tools tackle this issue, and this is what I found:

I share your concerns, though, and, to be honest, I was quite surprised to find that this seems to be a common practice.

To make the tests independent of their order, we could set $HOME at the beginning of the test suite so that all tests share the same environment.

@extrawurst
Copy link
Owner

@cruessler thanks for researching this. Ok lets go ahead with this approach, but let's do one more thing: Let's limit the impact of this change to the test that requires this instead of all using init_repo_empty.

We should make a utility that helps us set the env and protect it using a mutex guard that we can use to have multiple tests run in serial that depend on this behaviour, also this utility can revert the changes to env when dropped at the end of the test. Does that make sense to you?

can you make those changes and mark the PR as ready to review?

@cruessler
Copy link
Contributor Author

@extrawurst Sounds good to me! I'll update the PR in the next few days.

@cruessler
Copy link
Contributor Author

cruessler commented Sep 19, 2020

It looks like changing $HOME just for one test is not trivial. This is due to the following facts:

  • libgit2 has some global state that is initialized only once. This happens e. g. on the first call to Repository::init.
  • The initialization calls git_libgit2_init which sets up some global state.
  • In particular, the current value of $HOME is read and cached.

That means that whatever value $HOME had when Repository::init was first called will be used for further calls to repo.config(), among others. Effectively, all tests within the same process run with the same value for $HOME.

I briefly tried rusty-fork, but could not get it to work quickly.

@extrawurst
Copy link
Owner

@cruessler omg why do they make it so hard on us? :)
Look like we need to call git_libgit2_shutdown (https://github.com/rust-lang/git2-rs/blob/master/libgit2-sys/lib.rs#L1829) before we run a test that is HOME sensitive cause it is supposed to wipe clean those caches, right?

@cruessler
Copy link
Contributor Author

@extrawurst Looks like that is not an option, either. :-) We would have to depend on libgit2-sys in asyncgit which produces the following error message:

error: multiple packages link to native library `git2`, but a native library can be linked only once

I searched far and wide, but git_libgit2_shutdown does not seem to be exposed by git2 itself, so there’s no way to call it as far as I can see.

@extrawurst
Copy link
Owner

looks like u have an opportunity to become a git2-rs contributor :D

@cruessler
Copy link
Contributor Author

@extrawurst There is already an issue at git2-rs regarding environment variables. They’re considering mentioning this behaviour in the docs, so I don’t have the impression that git2-rs will be exposing git_libgit2_shutdown anytime soon. :-)

@extrawurst
Copy link
Owner

@cruessler as far as I can see no one ever raised the idea of exposing shutdown so I did now: rust-lang/git2-rs#550 (comment)

@extrawurst
Copy link
Owner

@cruessler also maybe this change is relevant for us: rust-lang/git2-rs#656 ?

@cruessler
Copy link
Contributor Author

@cruessler also maybe this change is relevant for us: rust-lang/git2-rs#656 ?

Thanks for the hint! I just checked locally, and on my machine the issue was solved and the new tests were green. I’ll update the branch, so we can see what CI says.

@cruessler
Copy link
Contributor Author

There is only one downside: set_search_path is unsafe and asyncgit forbids unsafe code.

@extrawurst
Copy link
Owner

@cruessler well that's a concession I can make. can you quickly add that to the changelog aswell, then I can merge it 👍

@cruessler
Copy link
Contributor Author

@extrawurst Great, done!

@extrawurst extrawurst marked this pull request as ready for review February 4, 2021 17:29
@extrawurst extrawurst merged commit fe0c2f5 into extrawurst:master Feb 4, 2021
@extrawurst
Copy link
Owner

@cruessler Thanks❤️

@cruessler cruessler deleted the allow-undefined-name branch May 13, 2021 12:43
extrawurst pushed a commit that referenced this pull request May 27, 2021
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.

None yet

2 participants