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

Explicitly specify git directory when running git #15

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from

Conversation

Kingdutch
Copy link

@Kingdutch Kingdutch commented Sep 29, 2021

Backstory

This was an interesting one track down. The symptom was that PHPStan only worked
when run directly, but not when run as part of a git invoked workflow (e.g. through
git rebase --exec).

The cause was that phpstan-drupal includes a file from the Drupal framework that queries
the runner to figure out which PHPUnit version is being used.

The version returned when running git did not match the actual PHPUnit version installed
which caused the alias that Drupal created to a PHPUnit bridge class to break.

Problem

The Version class uses a git command to find the tag of the currently installed package
version for packages that composer has checked out from git. This works when executed
directly.

However, when used in a git based workflow such as git rebase --exec or git bisect then
this fails. The cause is that for those commands git will add environment variables that specify
the GIT_DIR on which its performing those workflows, so that moving around and calling git
commands still operates according to the git repository the workflow is being executed on.

As a result when Version calls git describe --tags this does not use the .git folder in the
working directory of proc_open but instead uses the git folder for which the git workflow is
in progress.

Solution

To remedy this the Version class should specify --git-dir directly. A few lines above we already
know explicitly what git directory we're interested in. Specifying the argument to git overrides any
environment variables that may be set. This allows the library to work in automated git workflows
invoked from other repositories.

@sebastianbergmann
Copy link
Owner

Can you please target the 3.0 branch? Thanks!

@Kingdutch
Copy link
Author

Done :D

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